我按照AngularJS Multiple ng-app within a page
中的代码进行操作我不知道我错过了什么。
var reviewApp = angular.module("reviewApp", []);
var reviewApp2 = angular.module("reviewApp2", []);
reviewApp.controller("reviewCtrl",
function ShippingAddressCtrl($scope, $http) {
$scope.name='leo1';
});
reviewApp2.controller("productController",
function ProductController($scope, $http) {
$scope.name1='leo2';
});
angular.bootstrap(document.getElementById("div2"),['reviewApp2']);
答案 0 :(得分:9)
当你引导多个应用程序时,你不能多次使用ng-app
属性,angular会在标记中取第一个并自动引导它,所有其他ng-app
被忽略而你有手动引导它们
var reviewApp = angular.module("reviewApp", []);
var reviewApp2 = angular.module("reviewApp2", []);
reviewApp.controller("reviewCtrl",
function ShippingAddressCtrl($scope, $http) {
$scope.name='leo1';
});
reviewApp2.controller("productController",
function ProductController($scope, $http) {
$scope.name1='leo2';
});
angular.element(document).ready(function() {
angular.bootstrap(document.getElementById("div1"),['reviewApp']);
angular.bootstrap(document.getElementById("div2"),['reviewApp2']);
});
HTML
<div id="div1">
<div ng-controller="reviewCtrl">{{name}}</div>
</div>
<div id="div2">
<div ng-controller="productController">{{name1}}</div>
</div>