Angular Interview Questions and Answers
Question - 1 : - What is AngularJS?
Answer - 1 : - AngularJS is a JavaScript framework used for creating single web page applications. It allows you to use HTML as your template language and enables you to extend HTML's syntax to express your application's components clearly.
Question - 2 : - What are the key features of AngularJS?
Answer - 2 : - The key features of AngularJS are:
• Scope
• Controller
• Model
• View
• Services
• Data Binding
• Directives
• Filters
• Testable
Question - 3 : - Explain function scope in AngularJS
Answer - 3 : - Scope refers to the application model. It acts like a glue between the application controller and the view. Scopes are arranged in a hierarchical structure and impersonate the DOM (Document Object Model) structure of the application. It can watch expressions and propagate events.
Question - 4 : - Explain services in AngularJS
Answer - 4 : - AngularJS services are the singleton objects or functions that are used for carrying out specific tasks. It holds some business logic
Question - 5 : - ) What is Angular Expression? Explain the key difference between angular expressions and JavaScript expressions
Answer - 5 : - Like JavaScript, Angular expressions are code snippets that are usually placed in binding such as {{ expression }}
The key difference between the JavaScript expressions and Angular expressions is:
• 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 generate TypeError or ReferenceError
• No Control Flow Statements: Loops, conditionals or exceptions cannot be used in an angular expression
• Filters: You can use filters to format data before displaying it.
Question - 6 : - How can you initialize a select box with options on page load?
Answer - 6 : - You can initialize a select box with options on page load by using ng-init directive.
•
Question - 7 : - ) What are directives? Name some of the most commonly used directives in AngularJS application
Answer - 7 : - A directive is something that introduces new syntax. They are like markers on the DOM element, which attaches a special behavior to it. In any AngularJS application, directives are the most important components.
Some of the commonly used directives are:
1) ng-model
2) ng-App
3) ng-bind
4) ng-repeat
5) ng-show
Question - 8 : - How Angular JS routes work?
Answer - 8 : - AngularJS routes enable you to create different URLs for different content in your application. Different URLs for different content enable the user to bookmark URLs to specific content. Each such bookmarkable URL in AngularJS is called a route
A value in Angular JS is a simple object. It can be a number, string, or JavaScript object. Values are typically used as configuration injected into factories, services, or controllers. A value should belong to an AngularJS module.
Injecting a value into an AngularJS controller function is done by adding a parameter with the same name as the value
Question - 9 : - What is data binding in AngularJS?
Answer - 9 : - Automatic synchronization of data between the model and view components is referred to as data binding in AngularJS. There are two ways for data binding
1. Data mining in classical template systems
2. Data binding in angular templates
Question - 10 : - ) What are the benefits of AngularJS?
Answer - 10 : - Benefits of AngularJS are:
• Registering Callbacks: There is no need to register callbacks. This makes your code simple and easy to debug.
• Control HTML DOM programmatically: Applications which are created using Angular are not required to manipulate the DOM.
• Transfer data to and from the UI: AngularJS helps to eliminate almost all of the boilerplate. It can validate the form, display errors, return to an internal model, and so on.
• No initialization code: With AngularJS, you can bootstrap your app easily. You can use auto injected services into your application in Guice.