Learn AngularJS
Angular js application
- What is $scope in AngularJS?$scope in AngularJS is an object which refers to an application model. It is an object that binds view (DOM element) with the controller. In controller, model data is accessed via $scope object. As we know, AngularJS supports MV* pattern, $scope object becomes the model of MV*. The $scope is a special JavaScript object. Both View and controller have access to the scope object. It can be used for communication between view and controller. Scope object contains both data and functions. Every AngularJS application has a $rootScope that is the top most scope created on the DOM element which contains the ng-app directive. It can watch expressions and propagate events.
- 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 Using rootscope we can set the value in one controller and read it from the other controller. The following is the sample code snippet,
- What is SPA (Single page application) in AngularJS?Single-Page Applications (SPAs) are web applications that load a single HTML page and dynamically update that page as the user interacts with the app. 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. A single HTML page here means UI response page from the server. The source can be ASP, ASP.NET, ASP.NET MVC, JSP and so on. A single-page web application, however, is delivered as one page to the browser and typically does not require the page to be reloaded as the user navigates to various parts of the application. This results in faster navigation, more efficient network transfers, and better overall performance for the end user.
- How to implement routing in AngularJS?Routing is a core feature in AngularJS. This feature is useful in building SPA (Single Page Application) with multiple views. In SPA application, all views are different Html files and we use Routing to load different parts of the application and it's helpful to divide the application logically and make it manageable. In other words, Routing helps us to divide our application in logical views and bind them with different controllers.
- Explain services in AngularJSAngularJS services are the singleton objects or functions that are used for carrying out specific tasks. It holds some business logic.
- What are directives? Name some of the most commonly used directives in AngularJS applicationA 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
- What is data binding in AngularJS?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 Data mining in classical template systems Data binding in angular templates
- Explain directives and their typesDuring compilation process, when specific HTML function is triggered, it is referred to as directive. It is executed when the compiler encounters it in the DOM. Different types of directives are: 1) Element directives 2) Attribute directives 3) CSS class directives 4) Comment directives.
- Explain injector in AngularJSAn injector is a service locator. It is used to retrieve object instances as defined by provider, instantiate types, invoke methods, and load modules. There is a single injector per Angular application, it helps to lookup an object instance by its name.
- What is the factory function in AngularJS?For creating the directive, factory method is used. It is invoked only once when the compiler matches the directive for the first time. By using $injector.invoke the factory method is invoked.
- What are the characteristics of "Scope"?To observer model mutations scopes provide APIs ($watch) To propagate any model changes through the system into the view from outside of the Angular realm A scope inherits properties from its parent scope, while providing access to shared model properties, scopes can be nested to isolate application components Scope provides context against which expressions are evaluated
- Explain the concept of scope hierarchyEach angular application consists of one root scope but may have several child scopes. As child controllers and some directives create new child scopes, an application can have multiple scopes. When new scopes are formed or created, they are added as a children of their parent scope. They also create a hierarchical structure similar to DOM.
4iv>