Interview :: Angular JS
Yes, we can perform it by injecting PHP in the required place. i.e.,
It will work only if we use PHP to render the HTML and the above JavaScript in < script > tag inside the PHP file.
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
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.
AngularJS contains $https: control, which works as a service to make ajax call to read data from the server. The server creates a database call to retrieve the desired records. AngularJS requires data in JSON format. Once the data gets ready, $https: can be used to retrieve the data from the server in the following manner.
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.
Deep linking is the method which allows us to encode the state of the application in the URL in such a way that it can be bookmarked. Then the application can further be restored from the URL to the same state.
When a page is loaded into the browser, several things happen:
- HTML document file gets loaded, and evaluated by the browser. AngularJS JavaScript file gets loaded, and the angular global object is created. Next, JavaScript file which is responsible for registering the controller functions is executed.
- AngularJS scans through the HTML to find AngularJS apps and views. Once the view is found, it connects that particular view to the corresponding controller function.
- AngularJS executes the controller functions. It further renders the views with data from the model populated by the controller, and the page gets ready.
No, there can't be more than one ng-app directive for a single AngularJS application.
The ng-app directive helps AngularJS application to make sure that it is the root element. In our HTML document, we can have only one ng-app directive. If there is more than one ng-app directive, then whichever appears first will be used.
The syntax for creating new date object is given below:
No, the parent controller cannot access the methods of child controller, but the child controller can access the methods of the parent controller.
Every AngularJS application contains a $rootScope, which is the top-most scope created on the DOM element. An application can contain only one $rootScope, which will be shared among all its components. Every other scope is considered as its child scope. It can watch expressions and propagate events. By using the root scope, one can set the value in one controller and read it from the other controller.