Scope (scope) is the link between HTML (view) and JavaScript (Controller).
Scope is an object that has methods and properties available.
Scope can be applied to views and controllers.
Scope is a model.
Scope is a JavaScript object with properties and methods that can be used in views and controllers.
1 <DivNg-app= "MYAPP"Ng-controller= "Myctrl">2 <inputNg-model= "Name">3 <H1>{{Greeting}}</H1>4 <ButtonNg-click= "SayHello ()">Point Me</Button>5 </Div>6 <Script>7 varapp=Angular.module ('myApp',[]);8 App.controller ('Myctrl',function($scope) {9 $scope. Name="Zhouli";Ten $scope. SayHello= function(){ One $scope. Greeting= 'Hello' +$scope. Name+ '!'; A }; - }); - </Script>
Rootscope can be applied to the entire application and is the bridge of scope in each controller. Values defined with Rootscope can be used in each contrller.
1 <DivNg-app= "MYAPP"Ng-controller= "Myctrl">2 <H1>{{LastName}}</H1>3 <ul>4 <Ling-repeat= "x in Names">{{X}} {{LastName}}</Li>5 </ul>6 </Div>7 <Script>8 varapp=Angular.module ('myApp',[]);9 App.controller ('Myctrl',function($scope, $rootScope) {Ten $scope. Names= ['Email','Tobias','Linus']; One $rootScope. LastName= 'Refsnes'; A }); - </Script>
AngularJS---Scope