Monday, 6 June 2016

Detail information about Scopes in Angular Js

In this post we are going to study about scopes in angular js in detail. $scope is an instance of a Scope, Scope can be created and destroyed , scope creates tree like relationship for the model in the DOM tree.In angular js $rootScope is the Parent of all scopes.

The $rootScope instance is created when application gets loaded, a new scope was created for every controller, The syntax for creating a new scope is $scope.$new(), to destroy the scope use the $scope.$destroy();

For example :

var mainController = app.controller('mainController'function ($scope) {

    $scope.Data = 12;


Here in this controller creation we are injecting the Scope to the function. ng-controller directive is also one of the directive which creates scopes automatically.

No comments:

Post a Comment