*
Previous AngularJS-QA-4 AngularJS-QA-6 Next

AngularJS Question Answers - 5

Question: Difference between ng-bind and ng-bind-html?
Answer: ng-bind binds the content of an HTML element to application data. Where as the ng-bind-html binds the inner HTML of an HTML element to application data, and also removes dangerous code from the HTML string.
Question: To specify a behavior on blur events, which directive is used?.
Answer: ng-blur is used to specify a behavior on blur events.
Question: Explain what are factory method in angularJs?
Answer: Factory method are used to create the directive. It is invoked only once, when compiler matches the directive for the first time.
Question: How does the digest phase work?
Answer: In a nutshell, on every digest cycle all scope models are compared against their previous values. That is dirty checking. If change is detected, the watches set on that model are fired. Then another digest cycle executes, and so on until all models are stable.

It is probably important to mention that there is no “.$digest()” polling. That means that every time it is being called deliberately. As long as core directives are used, we don’t need to worry, but when external code changes models the digest cycle needs to be called manually. Usually to do that, “.$apply()” or similar is used, and not “.$digest()” directly.
Question: What is the purpose of the directive 'ng-if'?
Answer: ng-if: Removes the HTML element if a condition is true.
Question: What is the purpose of the directive 'ng-class-odd'?
Answer: ng-class-odd: Same as ng-class, but will only take effect on odd rows.
Question: What is the purpose of the directive 'ng-click'?
Answer: ng-click: Defines the behavior when an element is clicked.
Question: Explain what is services in AngularJS ?
Answer: In AngularJS services are the singleton objects or functions that are used for carrying out specific tasks. It holds some business logic and these function can be called as controllers, directive, filters and so on.
Question: What is a digest cycle in AngularJS?
Answer: in each digest cycle Angular compares the old and the new version of the scope model values. The digest cycle is triggered automatically. We can also use $apply() if we want to trigger the digest cycle manually.
Question: Where should we implement the DOM manipulation in AngularJS?
Answer: In the directives. DOM Manipulations should not exist in controllers, services or anywhere else but in directives.
Back to Index
Previous AngularJS-QA-4 AngularJS-QA-6 Next
*
*