A word summary:
$rootScope is active for the global scope
$scope only takes effect for the current controller scope
Use the following example to prove the above statement:
Define a module named MyApp
var myApp = angular.module (' myApp ', []);
Create Onecontroller and Twocontroller these two controller
Onecontroller Incoming $scope and $rootscope
Myapp.controller (' Onecontroller ', [' $scope ', ' $rootScope ', function ($scope, $rootScope) {
//local variables, $scope is displayed only in Onecontroller
. One_language = ' Python ';
Global variables, you can call
$rootScope. Language = ' go ';
}]);
Twocontroller only incoming $scope
Myapp.controller (' Twocontroller ', [' $scope ', function ($scope) {
//local variable, $scope is displayed only in Twocontroller
. Two_ Language = ' Java ';
}];
HTML tag Content
<span ng-app= "myApp" >
<style>
div{margin-top:15px;border:2px solid rebeccapurple;width:400px;}
</style>
<div>
The results displayed
Summarize
The above is the full content of this article, please take a closer look at the above code, which helps you understand. If you have questions, you can leave a message and thank you for your support for the cloud-dwelling community.