gpt4 book ai didi

javascript - 同一页面上有两个 Angular 应用程序 - 一次只能运行一个

转载 作者:行者123 更新时间:2023-11-28 19:33:53 25 4
gpt4 key购买 nike

我在一个页面中有两个 Angular 应用程序 block 。每个都单独工作,但是当我尝试同时运行两个时,只有第一个工作。

<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”可以工作。

详细

Fiddle here

最佳答案

https://docs.angularjs.org/api/ng/directive/ngApp

Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. To run multiple applications in an HTML document you must manually bootstrap them using angular.bootstrap instead. AngularJS applications cannot be nested within each other.

关于javascript - 同一页面上有两个 Angular 应用程序 - 一次只能运行一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26255843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com