| AngularJS-QA-8 | AngularJS-QA-10 | |
AngularJS Question Answers - 9 |
| Question: | What is the purpose of the directive 'ng-submit'? |
| Answer: | ng-submit: Specifies expressions to run on onsubmit events. |
| Question: | What is the purpose of the directive 'ng-switch'? |
| Answer: | ng-switch: Specifies a condition that will be used to show/hide child elements. |
| Question: | What is the purpose of the directive 'ng-transclude'? |
| Answer: | ng-transclude: Specifies a point to insert transcluded elements. |
| Question: | What is the purpose of the directive 'ng-value'? |
| Answer: | ng-value: Specifies the value of an input element. |
| Question: | Can angular applications (ng-app) be nested within each other? |
| Answer: | No. AngularJS applications cannot be nested within each other. |
| Question: | Can AngularJS have multiple ng-app directives in a single page? |
| Answer: | No. Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. If another ng-app directive has been placed then it will not be processed by AngularJS and we will need to manually bootstrap the second app, instead of using second ng-app directive. |
| Question: | How to check a reference is an array in AngularJS? |
| Answer: |
Use angular.isArray() which returns true if the reference is an array
var chkArray = [415,203,23,54,75,46];
var chkStr = "www.gktoall.com";
document.write(angular.isArray(chkArray));
Document.write("</br>");
document.write(angular.isArray(chkStr));
Output:
true false |
| Question: | What does the ng-change? |
| Answer: | Specifies an expression to evaluate when content is being changed by the user. |
| Question: | What are the basic steps to unit test an AngularJS filter? |
| Answer: |
Step-1. Inject the module that contains the filter. Step-2. Provide any mocks that the filter relies on. Step-3. Get an instance of the filter using $filter('yourFilterName'). Step-4. Assert your expectations. |
| Question: | Explain what is difference between angular expressions and JavaScript expressions? |
| Answer: |
The difference between the JavaScript expressions and Angular expressions are:
Context : In Angular, the expressions are evaluated against a scope object, while the Javascript expressions are evaluated against the global window. Forgiving: In Angular expression evaluation is forgiving to null and undefined, while in Javascript undefined properties generates TypeError or ReferenceError. No Control Flow Statements: Loops, conditionals or exceptions cannot be used in an angular expression. Filters: To format data before displaying it you can use filters. |
| AngularJS-QA-8 | AngularJS-QA-10 | |