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 AngularJS  ng-app = "ungdungAngularjs" ng-controller = "nhanvienController" > 
 {{message}} 
{{type}} ng-controller = "nhanvienITController" >
 {{message}} 
{{type}}

ng-controller="nhanvienBHController">

{{message}}
{{type}} src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">

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

4 ★ | 2 Vote

May be interested

  • Create the first AngularJS applicationCreate the first AngularJS application
    to 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 AngularJSMultilingual (i18n) in AngularJS
    angularjs 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 in AngularJS
    expression 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 AngularJSController component in AngularJS
    an angularjs application works primarily based on the controller component to control the flow of data in the application.
  • MVC structure in AngularJSMVC structure in AngularJS
    model view controller or mvc is a popular call, a software design model for web-based applications.
  • Create the table in AngularJSCreate the table in AngularJS
    table 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 MobileQuick Change Scope in PUBG Mobile
    with 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 PythonScopes in Python
    what 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 CScope rules in programming C
    a 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 AngularJSInclude syntax in AngularJS
    html does not support embedding html web pages in html pages. to achieve this function, the following methods can be used: