我在Angular使用Smart-table在source table 的時後, 因為想要利用 filter的功能將過濾後的資料集拿到不同區塊使用, 把function 寫到ng-repeat裡面。 像是
st-safe-src="rowList | filter:showFn"
這一個粗心的錯誤會讓angular產生Error: error:infdig,Infinite $digest Loop的錯誤訊息
這個訊息的產生原因是當ng-repeat每跑一次, 會觸發值改變,所以又會觸發$digest. 然後當$digest的次數太多之後,就會發生錯誤訊息, 執行效率也會變得非常的不好。
所以回到angularjs的頁面裡找到這個https://docs.angularjs.org/error/$rootScope/infdig
下面的說明就有提到這個現象.
Since getUsers() returns a new array, Angular determines that the model is different on each $digest cycle, resulting in the error. The solution is to return the same array object if the elements have not changed:
解決的方式就是不要st-safe-src裡面寫filter,st-stafe-src中盡量保持原始資料. 但如果要達到相同的效果, 可以先將過濾後的結果存到一個變數中, 然後在去操作那個變數就不會產生這個錯誤了
ng-repeat="item in (someVar = model | filter: someCondition)"
文章標籤
全站熱搜
