var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $rootScope) {
$scope.names = ["Emil", "Tobias", "Linus"];
$rootScope.lastname = "Refsnes";
});
var app2 = angular.module('myApp2111', []);
app2.controller('myCtrl2', function($scope,$rootScope) {
$scope.names = ["Emil", "Tobias", "Linus"];
$rootScope.lastname = "Refsnes";
});
angular.bootstrap(document.getElementById("myApp2111"), ['myApp2111']);
//angular.bootstrap(document.getElementById(ID), [ID]);
//angular.bootstrap($("dir"),['dir']);
//这是两个,多个的话继续加一行 angular.bootsara
也可以:在第二个ng-app接管的div上要加一个id属性dir并且去掉第二个ng-app
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style> </style>
<script src="js/jquery.min.js"></script>
<script src ="js/angular.js"></script>
</head>
<body >
<div ng-app="myapp">
<hello></hello>
</div>
<div id="dir" >
<dir></dir>
</div>
<script >
var app = angular.module("myapp",[]);
app.directive("hello",function(){
return {
restrict:"E",
template:'<h1>Hello angular</h1>',
replace:true
}
});
var app2 = angular.module("dir",[]).run(function($templateCache){
$templateCache.put("header.html","<h2>use templateCache</h2>");
});
app2.directive("dir",function($templateCache){return {
restrict:"E",
template:$templateCache.get("header.html"),
replace:true
}});
angular.bootstrap($("dir"),['dir']);
</script>
</body>
</html>
做一个像马老师一样温文尔雅的人;
浙公网安备 33010602011771号