<!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就是一个模块,ng-app可以写在div等小标签中, m1.controller('Aaa',function($scope){//控制器名字是Aaa,函数是function,就类似于 function Aaa($scope){ $scope.name = 'hello';} $scope.name = 'hello'; }); m1.controller('Bbb',function($scope){ $scope.name = 'hi'; }); //为了防止压缩后function形参$scope改变成$s,就要下面的写法。 var m1 = angular.module('myApp',[]); m1.controller('Aaa',['$scope',function($scope){ $scope.name = 'hello'; }]); m1.controller('Bbb',['$scope',function($scope){ $scope.name = 'hi'; }]); /* function Aaa($scope){ $scope.name = 'hello'; } function Bbb($scope){ $scope.name = 'hi'; }*/ </script> </head> <body> <div ng-controller="Aaa"> <p>{{name}}</p> </div> <div ng-controller="Bbb"> <p>{{name}}</p> </div> </body> </html>
本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5734798.html,如需转载请自行联系原作者