| AngularJS-QA-6 | AngularJS-QA-8 | |
AngularJS Question Answers - 7 |
| Question: | What is the purpose of the directive 'ng-mousemove'? |
| Answer: | ng-mousemove: Specifies a behavior on mousemove events. |
| Question: | What is the purpose of the directive 'ng-mouseover'? |
| Answer: | ng-mouseover: Specifies a behavior on mouseover events. |
| Question: | How to check a references are equal in AngularJS? |
| Answer: |
Use angular.equals() which returns true if two references are equal
var myObj1 = {'name' : 'Shiva', 'age' : '28'}
var myObj2 = {'city' : 'Benguluru', 'phone' : '080-11111111'}
var myStr1 = "www.gktoall.com";
var myStr2 = "www.google.co.in";
document.write(angular.equals(myObj1, myObj1));
document.write("</br>");
document.write(angular.equals(myObj1, myObj2));
document.write("</br>");
document.write(angular.equals(myStr1, myStr1));
document.write("</br>");
document.write(angular.equals(myStr1, myStr2));
document.write("</br>");
Output:true false true false |
| Question: | What is the purpose of the directive 'ng-mouseenter'? |
| Answer: | ng-mouseenter: Specifies a behavior on mouseenter events. |
| Question: | What is the purpose of the directive 'ng-mouseleave'? |
| Answer: | ng-mouseleave: Specifies a behavior on mouseleave events. |
| Question: | How to convert string to lower case without using filter? |
| Answer: |
Use the angular.lowercase() function which converts a string to lowercase ex:
var str = "UPPER CASE STRING";
document.write(angular.lowercase(str));
Output is : “upper case string”
|
| Question: | How to convert string to upper case without using filter? |
| Answer: |
Use the angular.uppercase() function which converts a string to uppercase ex:
var str = "lower case string";
document.write(angular.uppercase(str));
Output is : “LOWER CASE STRING”
|
| Question: | What is the purpose of the directive 'ng-mouseup'? |
| Answer: | ng-mouseup: Specifies a behavior on mouseup events. |
| Question: | How to process each value in object collection in Angular JS? |
| Answer: |
User angular.forEach() function which executes a function for each element in an object or array.
The first parameter to the iterator in forEach is the value and second is the key of the object.
angular.forEach(objectToIterate, function(value, key) {
/* do something for all key: value pairs */
});
|
| Question: | Which means of communication between modules of your application are easily testable? |
| Answer: |
Using a service is definitely easy to test. Services are injected, and in a test either a real service can be used or it can be mocked.
Events can be tested. In unit testing controllers, they usually are instantiated. For testing events on $rootScope, it must be injected into the test. Testing $rootScope against the existence of some arbitrary models is testable, but sharing data through $rootScope is not considered a good practice. For testing direct communication between controllers, the expected results should probably be mocked. Otherwise, controllers would need to be manually instantiated to have the right context. |
| AngularJS-QA-6 | AngularJS-QA-8 | |