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.
Follow tutorialspoint
Previous article: View component in AngularJS
Next article: The Service in AngularJS
You should read it
May be interested
- The Service in AngularJSangularjs supports the concept of seperation of concerns - divide to use service structure. service is javascript functions and is responsible for certain tasks.
- Multilingual (i18n) in AngularJSangularjs provides multi-lingual functions (i18n) with 3 types of filters, currency, date and number. we just need to combine the js corresponding to the location depending on the country. by default it will attach to the location in the web browser.