What do you understand by linking function? Explain its type.
Link is used for combining the directives with a scope and producing a live view. The link function is used for registering DOM listeners as well as updating the DOM. The linking function is executed as soon as the template is cloned.
There are two types of linking function:
- Pre linking function
Pre-linking functions are executed before the child elements are linked. This method is not considered as a safe way for DOM transformation. - Post linking function
Post-linking functions are executed after the child elements are linked. This method is a safe way for DOM transformation.
What are the different types of directives available in AngularJS?
AngularJS provides support for creating custom directives for the following type of elements:
- Element Directive
Element directives are activated when a matching element is encountered. - Attribute
Attribute directives are activated when a matching attribute is encountered. - CSS
CSS directives are activated when a matching CSS style is encountered. - Comment
Comment directives are activated when a matching comment is encountered.
What do you understand by strict conceptual escaping?
AngularJS treats all the values as untrusted/ unsecured in HTML or sensitive URL bindings. AngularJS automatically runs security checks while binding untrusted values. It throws an error if it cannot guarantee the security of the result. This type of behavior depends on contexts: HTML can be sanitized, but template URLs cannot.
To illustrate this, consider the following directive
Ng-bind-html
It renders its value directly as HTML. When there is an untrusted input, AngularJS will try to sanitize it before rendering if a sanitizer is available. We will need to mark it as trusted to bypass sanitization and render the input.
Do you think that parent controller can access the methods of child controller or vice versa?
No, the parent controller cannot access the methods of child controller, but the child controller can access the methods of the parent controller.
What are the disadvantages of AngularJS?
There are some drawbacks of AngularJS which are given below:
- JavaScript Dependent
If end-user disables JavaScript, AngularJS will not work. - Not Secured
It is a JavaScript-based framework, so it is not safe to authenticate the user through AngularJS only. - Time Consumption in Old Devices
The browsers on old computers and mobiles are not capable or take a little more time to render pages of application and websites designed using the framework. It happens because the browser performs some supplementary tasks like DOM (Document Object Model) manipulation. - Difficult to Learn
If you are new in AngularJS, then it will not be easy for you to deal with complex entities such as Quite layered, hierarchically and scopes. Debugging the scope is believed a tough task for many programmers.
What are the directives in AngularJS?
Directives are the markers on DOM element which are used to specify behavior on that DOM element. All AngularJS directives start with the word “ng”. There are many in-built directives in AngularJS such as “ng-app”, “ng-init”, “ng-model”, “ng-bind”, “ng-repeat” etc.
- ng-app
The ng-app directive is the most important directive for Angular applications. It is used to locate the beginning of an Angular application for AngularJS HTML compiler. It marks the HTML elements that Angular intends to make the root element of the application. The custom attributes use spinal-cases, whereas the corresponding directives follow the camelCase. If we do not use this directive and try to process other directives, it gives an error. - ng-init
The ng-init directive is useful for initializing the data variable’s inline statement of an AngularJS application. Therefore, those statements can be used in the specified blocks where we can declare them. A directive ng-init is like a local member of the ng-app directive, and it may be a single value or a group of the values. It directly supports JSON data. - ng-model
The ng-model directive binds the values of HTML elements such as input, select, textarea to the application data. It provides two-way binding behavior with the model value. Sometimes, it is also used for databinding. - ng-bind
The ng-bind directive is used to bind the model/variable’s value to HTML controls of an AngularJS application. It can also be used with HTML tags attributes like:, and more but it does not support two-way binding. We can only check the output of the model values. - ng-repeat
The ng-repeat directive is used to repeat HTML statements. It works the same as for each loop in C#, Java or PHP on a specific collection item like an array.
What is a template in AngularJS?
A template consists of HTML, CSS, and AngularJS directives, which are used to render the dynamic view. It is more like a static version of a web page with some additional properties to inject and render that data at runtime. The templates are combined with information coming from model and controller.
What do you know about injector?
An injector is referred to as a service locator. It is used to receive object instances as defined by the providers, invoke methods, instantiate types, and load modules. Each Angular application consists of a single injector which helps to look upon an instance by its name.
Explain the compilation process of AngularJS?
Angular’s HTML compiler allows us to teach the browser, new HTML syntax. It also allows the developer to attach new behavior or attributes to any HTML element known as directives. AngularJS compilation process automatically takes place in the web browser. It does not contain any server-side or pre-compilation procedure.
AngularJS uses <$compiler> service for the compilation process of an Angular HTML page. Its compilation process starts after the HTML page (static DOM) is completely loaded.
It occurs in two phases:
- Compile
It checks into the entire DOM and collects all of the directives. - Link
It connects the directives with a scope and produces a live view.
The concept of compile and link has been added from C language. The code is compiled and then linked.
What do you know about internationalization? How will you implement internationalization in AngularJS?
Internationalization is the method for showing locale-specific information on a website. Consider a website displaying content in the English language in the United States and Danish in France.
AngularJS has inbuilt internationalization support for three types of filters:
- Currency
- Date
- Numbers
We need to incorporate the corresponding JS according to the locale of the country. By default, it is configured to handle the locale of the browser.