我在页面中有两个角度应用程序块。每个人都单独工作,但是当我尝试同时运行时,只有第一个工作。
<body>
<div ng-app='myApp' class="Freight">
<div ng-controller="MainCtrl">
<div>
<ul>
<li ng-repeat="prdElement in palletElement">
<span>
<input type="text" ng-model="prdElement.name" placeholder="Name" required />
</span>
<ul>
<li ng-repeat="elemnt in prdElement.product">
<div class="prd-box">
<span>
<input type="text" ng-model="elemnt.Code" placeholder=" Code" required />
</span>
<span>
<input type="text" ng-model="elemnt.name" placeholder=" Description" required />
</span>
<span>
<input type="text" ng-model="elemnt.class" placeholder=" Class" required />
</span>
<span>
<input type="text" ng-model="elemnt.quantity" placeholder=" Quantity" required />
</span>
<span>
<input type="text" ng-model="elemnt.weight" placeholder=" Weight" required />
</span>
<span ng-hide="elemnt.length == 1">
<a href="#" ng-click="prdElement.product.splice($index, 1)">Remove Item</a>
</span>
</div>
</li>
<li>
<a href="#" ng-click="newPrdItem(prdElement,$event)">Add Item</a>
</li>
</ul>
<a href="#" ng-click="newPalletItem(palletElement,$event)">Add Pallet</a>
<a href="#" ng-click="prdElement.splice($index, 1)">Remove Pallet</a>
<a href="#">Remove Pallet</a>
</li>
</ul>
</div>
<div>
<button ng-click="showitems($event)">Submit</button>
</div>
<div id="displayitems">{{palletElement}}</div>
</div>
</div>
<div ng-app='PackageApp' class="Freight">
<div ng-controller="PackageCtrl">
<div>
<ul>
<li ng-repeat="prdPackageElement in packageElement">
<span>
<input type="text" ng-model="prdPackageElement.name" placeholder="Name" required />
</span>
</li>
</ul>
</div>
<!--<div>
<button ng-click="showitems($event)">Submit</button>
</div>
<div id="displayitems" style="visibility:hidden;">
{{prdElement}}
</div>-->
</div>
</div>
在这种情况下,只有第一个应用'MyApp'可以使用。
详细
答案 0 :(得分:3)
https://docs.angularjs.org/api/ng/directive/ngApp
每个HTML只能自动引导一个AngularJS应用程序 文献。文档中找到的第一个ngApp将用于定义 作为应用程序自动引导的根元素。要运行多个 HTML文档中的应用程序必须手动引导它们 使用angular.bootstrap代替。 AngularJS应用程序不可能 相互嵌套。