我有這條線在我的模板:你可以在角度綁定中使用array.filter嗎?
<span>{{ data.things.find(r => { return r.id == 5 }).description }}</span>
當我運行它,我得到以下錯誤:
Parser Error: Bindings cannot contain assignments at column...
這是否意味着你不能在綁定使用array.find
而來?
我知道我的對象有值,表達式在觀察窗口中計算。 有什麼建議嗎?
編輯: 雖然this question及其答案將解決這個問題,我不認爲他們是重複的。這個問題特定於篩選到一個較小的列表,也許是一個記錄,因爲我的問題每次都得到一條記錄。 @ Thierry-Templier的回答在這方面看起來不錯,我喜歡它如何清潔html。
[angular 2 sort and filter]可能的重複(http://stackoverflow.com/questions/32882013/angular-2-sort-and-filter) –