这种方式,一旦页面需要多个初始化时,可以用bootstrap,指令只能进行一次初始化操作
需要进行多个初始化时使用!!!!
<script>
var i=0;
var m1 = angular.module('myApp1',[]);
var m2 = angular.module('myApp2', []);
m1.controller("myCtrl1", function($scope){
$scope.name = "xiaopang";
})
m2.controller("myCtrl2", function($scope){
$scope.name = 'lengyu';
})
document.onclick = function(){
i++;
console.log(i)
var aDiv = document.getElementsByTagName("div");
// angular.bootstrap(aDiv[0], ["myApp1"]);
angular.bootstrap(aDiv[1], ["myApp2"]); //绑定到第二个div上
}
</script>
</head>
<body>
<div id="div1" ng-app="myApp1" ng-controller="myCtrl1">
<!-- <p>{{name}}</p>-->
<p ng-bind="name"></p>
</div>
<div id="div2" ng-controller="myCtrl2">
<!--<p>{{name}}</p>-->
<p ng-bind="name"></p>
</div>
</body>