AngularJS Interview Questions

17. Explain the difference between ng-show/ng-hide and ng-if directives?
ng-show/ng-hide will insert the DOM element, but will display/hide it based on the condition.
ng-if will not insert the DOM element until the condition is not fulfilled.
ng-if is better when we needed the DOM to be loaded conditionally.

18. How to improve performance in an AngularJS app?
a)Disabling debug data

myApp.config(function ($compileProvider) {

b)Enabling strict DI mode.

19. What is “$rootScope” in AngularJS?
A scope provides a separation between View and its Model. Every application has a $rootScope provided by AngularJS and every other scope is its child scope.
Using rootscope, we can set the value in one controller and read it from the other controller.

20. What is SPA?
A single-page application (SPA) is a web application or web site that interacts with the user by dynamically rewriting the current page rather than loading entire new pages from a server. This approach avoids interruption of the user experience between successive pages, making the application behave more like a desktop application. In an SPA, either all necessary code – HTML, JavaScript, and CSS – is retrieved with a single page load. SPAs use AJAX and HTML to create fluid and responsive web apps, without constant page reloads. However, this means much of the work happens on the client side, in JavaScript.