Home / Interview / Angular JS :: General Questions

Interview :: Angular JS

31) Can we set an Angular variable from PHP session variable without sending an HTTP request?

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.

32) 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

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.

33) How can someone make an ajax call using AngularJS?

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.

34) 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.

35) How will you explain deep linking in AngularJS?

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.

36) Describe the AngularJS boot process.

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.
37) Is it possible to have two ng-app directives for a single Angular application?

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.

38) What is the syntax for creating a new date object?

The syntax for creating new date object is given below:

39) 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.

40) Explain $rootScope in AngularJS.

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.