省掉了控制器
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <script src="angular.min.js"></script> <script> var m1 = angular.module(‘myApp‘,[]); /*m1.controller(‘Aaa‘,[‘$scope‘,function($scope){ $scope.name = ‘hello‘; }]); m1.controller(‘Bbb‘,[‘$scope‘,function($scope){ $scope.name = ‘hi‘; }]);*/ //当没有控制器的链接,就使用全局的方式,即使用run方法 m1.run([‘$rootScope‘,function($rootScope){ $rootScope.name = ‘hello‘; $rootScope.age = ‘20‘; }]); console.log( m1 ); </script> </head> <body> <div> <p>{{name}}</p> <p>{{age}}</p> </div> </body> </html>
时间: 2024-12-29 11:41:31