Angular在一个页面中使用两个ng-app的方法(二)
在上篇文章给大家介绍了Angular在一个页面中使用两个ng-app的方法,这种方法不太推荐,下面给大家介绍方法二,具体代码如下所示:
<!DOCTYPEhtml> <htmllang="en"> <head> <metacharset="utf-8"> <title>ng-app指令,angular找到第一个ng-app就不会再找了,在一个页面中只使用一个ng-app.</title> </head> <bodyng-app="myApp"> <inputtype="button"ng-controller="App1Controller"ng-click="do1()"value="按钮1"/> <inputtype="button"ng-controller="App2Controller"ng-click="do2()"value="按钮2"> <scriptsrc="bower_components/angular/angular.js"></script> <script> varmyApp1=angular.module('myApp1',[]); myApp1.controller('App1Controller',['$scope',function($scope){ $scope.do1=function(){ console.log(11111); }; }]); varmyApp2=angular.module('myApp2',[]); myApp2.controller('App2Controller',['$scope',function($scope){ $scope.do2=function(){ console.log(22222); }; }]); /** *myAppMod'myApp1','myApp2'ul; * *Description */ angular.module('myApp',['myApp1','myApp2']); </script> </body> </html>
就是用一个大的模块将两个小模块包起来。
以上所述是小编给大家介绍的Angular在一个页面中使用两个ng-app的方法(二),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!