1
我有一個複雜的指令,儘管我的應用程序使用了很多HTML頁面。它已經變得複雜,幷包含嵌套結構,所以我複製並粘貼到處都是:如何使用angularJS在HTML中分配(動態)變量
<card ng-repeat="card in deck"
scalex="card.scalex"
scaley="card.scaley"
...
<img ng-repeat="wait in [] | range:card.f" src="symbol.png" style="position:absolute; left:{{(13*$index + 3)}}px; z-index: 1;bottom:0px"></img>
...
<icon ng-repeat="icon in card.icons"
x="icon.x"
y="icon.y"
...
/>
</card>
然而,並非總是這個指令綁定到變量「卡」。因此,在複製和粘貼之後,我需要將大量任務從「card.bar」更改爲「foo.bar」。這是有點labourius和容易出錯。我想分配一個與foo具有相同狀態的綁定變量卡。然後,我不需要更改源文件,我保留複製和粘貼。
那麼有沒有一個班輪,我可以添加一個指令,在HTML中,將重新分配foo到卡?
你有沒有和'NG-init'? – TheHippo