demo.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>AngularJS</title> <script src="angular.min.js"></script> <!-- Introduce AngularJS framework--> </head> <body ng-app="App"> <div ng-controller="DemoController"> <h3>{{name}}</h3> </div> <script> var App = angular.module('App',[]); // Directly run (module) through the run method. (precedence) $rootScope root scope App.run(['$rootScope',function($rootScope) { $rootScope.name = 'Zhang San'; // $rootScope root scope (global scope) }]); // controller App.controller("DemoController",['$scope',function($scope) { $scope.name = 'Override variables in root scope'; //Each controller is equivalent to a function. $scope overrides variables in $rootScope (scope chain) }]); </script> </body> </html>