需要來自視圖內兩個位置的ng-repeat的數據。下面的代碼工作,但我不知道這是否是這樣做的方式。 (我是Angular的新手)。在一頁上使用相同的ng-repeat - 最佳實踐?
如果用戶點擊插座選項,插座產品將顯示。首先,我將產品加載到outlet-option下面,如果用戶點擊某個選項,則使用jQuery移動到productsWrapper。但後來我需要再次編譯它,這使我覺得有點麻煩。
只能有一個「#productsWrapper」和一個「.outlet」,所以我想出了兩次使用ng-repeat。但是,這是要走的路嗎?
<div id="productsWrapper">
<div ng-repeat="element in elements track by $index" class="products" style="display: none;" id="prod-{{element.wonelement_id}}">
<outlet-product ng-repeat = "option in element.options"
class = "product"
option-data = "option"
element-data= "element"
chosen-data = "chosen">
</outlet-product>
</div>
</div>
<div class="outlet">
<div ng-repeat="element in elements track by $index">
<outlet-option
element-data = "element"
option-data = "element.option"
chosen-data = "chosen"
app-settings = "app">
</outlet-option>
</div>
</div>
對我來說很好。 –