Scope in AngularJS
Scope is a special JavaScript object with the role of linking controllers and views. Scope contains information as model data. In the controller, model data can be accessed via the $ scope object.
Here are the important points of the above example.
$ scope is passed as the controller's first parameter in its constructor.
$ scope.message and $ scope.type are models used in HTML pages.
We set the values for the model and impact the Application Module with controller and nhanvienController.
We can define functions with $ scope.
Scope's inheritance in AngularJS
Scope is a separate controller. We define nested controllers so that the sub-controllers will inherit from the parent controllers.
Here are the main points through the above example.
We create the model variable value for nhanvienController.
We override the child controller's message as nhanvienITController. When "message" is used in nhanvienITController modules, the overwritten message value will be used.
For example
Below is an example for the above tutorial.
viduScope.html
Vi du Scope in AngularJS
Cavalier AngularJSng-app = "ungdungAngularjs" ng-controller = "nhanvienController" >
{{message}}
{{type}}ng-controller = "nhanvienITController" >
{{message}}
{{type}}
{{message}}
{{type}}
Result:
Open viduScope.html page on web browser. And see the results below.
Scope in AngularJS Picture 1
Follow tutorialspoint
Previous article: View component in AngularJS
Next article: The Service in AngularJS
You should read it
- What is AngularJS?
- Instructions for installing AngularJS
- The Service in AngularJS
- The Filter in AngularJS
- Directive in AngularJS
- Ajax in AngularJS
- Form in AngularJS
- The Module in AngularJS
- View components in AngularJS
- HTML DOM element in AngularJS
- Create the first AngularJS application
- Scope rules in programming C