| AngularJS-QA-13 | React-QA-1 | |
AngularJS Question Answers - 14 |
| Question: | What is the purpose of the directive 'ng-keyup'? |
| Answer: | ng-keyup: Specifies a behavior on keyup events. |
| Question: | What is the purpose of the directive 'ng-list'? |
| Answer: | ng-list: Converts text into a list. |
| Question: | How to create, register and retrieve an AngularJS module? |
| Answer: | Use angular.module() which creates, registers, or retrieves an AngularJS module |
| Question: | How to do deep copy in Angular JS? |
| Answer: | Use the angular.copy() function which creates a deep copy of an object or an array. |
| Question: | How to validate a text input field for a twitter username, including the @ symbol? |
| Answer: | Use the 'ngPattern' directive to perform a regex match that matches Twitter usernames. The same principal can be applied to validating phone numbers, serial numbers, barcodes, zip codes etc… |
| Question: | Can we have nested controllers in AngularJS? |
| Answer: | Yes, we can create nested controllers in AngularJS. Nested controllers are defined in hierarchical manner while using in View. |
| Question: | Can we create our own directives? |
| Answer: | YES. AngularJS allows us to create our own custom directive. |
| Question: | What should be the maximum number of concurrent “watches” for better performance? |
| Answer: | To reduce memory consumption and improve performance it is a good idea to limit the number of watches on a page to 2,000. |
| Question: | How to keep count of “watches” in AngularJS? |
| Answer: |
ng-stats is used to track the watch count and digest cycles.
Memory use and digest cycle performance are directly affected by the number of active watches. Therefore, it is best to keep the number of watches below 2,000. The open-source utility ng-stats gives developers insight into the number of watches Angular is managing, as well as the frequency and duration of digest cycles over time. |
| Question: | What is the role of services in AngularJS? |
| Answer: |
Services are the best way to evolve reusable API within and AngularJS app
AngularJS Services help create reusable components. A Service can be created either using the service() method or the factory() method. A typical service can be injected into another service or into an AngularJS Controller. |
| Question: | Explain few in built services in AngularJS? |
| Answer: |
Few of the inbuilt services in AngularJS are:
– $http service: The $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser’s XMLHttpRequest object or via JSONP – $log service: Simple service for logging. Default implementation safely writes the message into the browser’s console – $anchorScroll: it scrolls to the element related to the specified hash or (if omitted) to the current value of $location.hash() Understanding the purpose of AngularJS Services helps bring modularity to AngularJS code. |
| AngularJS-QA-13 | React-QA-1 | |