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
- Create the first AngularJS applicationto start, we start with creating the actual xinchao application by using angularjs, we will show you the specific parts of an angularjs application.
- 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.
- Expression in AngularJSexpression is used to bind application data to html tags. expression is written in {{expression}}. expression has a similar way of operating as the ng-bind directive.
- Controller component in AngularJSan angularjs application works primarily based on the controller component to control the flow of data in the application.
- MVC structure in AngularJSmodel view controller or mvc is a popular call, a software design model for web-based applications.
- Create the table in AngularJStable data is often repeated in natural order. in angularjs, ng-repeat directive can be used to draw tables easily. below is an example of how to use ng-repeat to create tables.
- Quick Change Scope in PUBG Mobilewith this feature, gamers change the scope instantly rather than having to open the bag and change scope to match the distance in pubg mobile.
- Scopes in Pythonwhat is scope in python? how to use scope in python? let's learn everything you need to know about scope in python with tipsmake.com.com!
- Scope rules in programming Ca scope in any program is an area in the program where a defined variable exists and outside of that range the variable cannot be accessed.
- Include syntax in AngularJShtml does not support embedding html web pages in html pages. to achieve this function, the following methods can be used: