AngularJS scope details and sample code, angularjs sample code
Range plays the role of its view connection controller as a special JavaScript Object. The range contains model data. In the controller, model data is accessed through the $ scope object.
<script> var mainApp = angular.module("mainApp", []); mainApp.controller("shapeController", function($scope) { $scope.message = "In shape controller"; $scope.type = "Shape"; });</script>
The following are important issues to consider in the preceding example.
$ Scope is used as the first parameter in its constructor to determine the metric to the Controller.
$ Scope. message and $ scope. type are the models they use on the HTML page.
We have set the model value to reflect the Controller shapeController of the application module.
We can define function functions in $ scope.
Inheritance Scope
The range is a specific controller. If we define a nested controller, then the Controller child will inherit the range controlled by its parent.
<script> var mainApp = angular.module("mainApp", []); mainApp.controller("shapeController", function($scope) { $scope.message = "In shape controller"; $scope.type = "Shape"; }); mainApp.controller("circleController", function($scope) { $scope.message = "In circle controller"; });</script>
The following are important issues to consider in the preceding example.
We set the model value in shapeController.
We overwrite the subcontroller circleController message. When the module of the controller circleController in a message is used, messages that are used for rewriting are used.
Example
The following example shows all the preceding commands.
TestAngularJS.html
Result
Open textangularjs.html in the webbrowser. The result is as follows.
The above is to sort out AngularJS scope information, and continue to add relevant information in the future. Thank you for your support for this site!