模块同时载入多个模式,html标签要去掉my-app
<!DOCTYPE HTML> <html> <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(‘myApp1‘,[]); var m2 = angular.module(‘myApp2‘,[]); m1.controller(‘Aaa‘,[‘$scope‘,function($scope){ $scope.name = ‘hello‘; }]); m2.controller(‘Bbb‘,[‘$scope‘,function($scope){ $scope.name = ‘hi‘; }]); document.onclick = function(){ var aDiv = document.getElementsByTagName(‘div‘); angular.bootstrap(aDiv[0],[‘myApp1‘]); angular.bootstrap(aDiv[1],[‘myApp2‘]); }; </script> </head> <body> <div ng-controller="Aaa"> <p>{{name}}</p> </div> <div ng-controller="Bbb"> <p>{{name}}</p> </div> </body> </html>
时间: 2024-10-01 05:06:00