3
我有一個ng-repeat,它像一個開關條件,告訴要渲染哪個模板。我正在使用ng - 如果在ng-repeat內部來實現這一點。問題?它仍然在評估ng中的模板 - 即使條件評估爲false,導致整個事情變得緩慢。有沒有一種方法可以防止在ng中評估模板 - 如果其條件評估爲false?
<div ng-repeat="i in ...">
<div ng-if="i == 'something1'">
if this is false, do not evaluate this entire stuff
.... some complex template goes here
</div>
<div ng-if="i == 'something2'">
if this is false, do not evaluate this entire stuff
.... another complex template goes here
</div>
</div>
如果裏面每個NG-如果是複雜的,有20毫微克,如果裏面NG重複,只有一個NG-如果計算結果爲真,那麼其他19個模板會浪費計算資源的模板。
我能做些什麼來減輕這種影響,而不訴諸於程序化方法,並且保持呈現模板的雙向綁定?