這對我來說並不完全清楚談論這個的時候,這裏(模板語法部分)究竟由Angular2文檔中的「副作用」的意思,例如:
Angular2文檔中的「副作用」是什麼意思?
Avoid side effects
As mentioned previously, evaluation of a template expression should have no visible side effects. The expression language itself does its part to keep you safe. You can't assign a value to anything in a property binding expression nor use the increment and decrement operators.
Of course, the expression might invoke a property or method that has side effects. Angular has no way of knowing that or stopping you.
The expression could call something like getFoo(). Only you know what getFoo() does. If getFoo() changes something and you happen to be binding to that something, you risk an unpleasant experience. Angular may or may not display the changed value. Angular may detect the change and throw a warning error. In general, stick to data properties and to methods that return values and do no more.
如何表達的評估可能有副作用,這可能對UI呈現或邏輯有什麼影響?