为什么混合插值和表达式是不好的做法 [英] Why mixing interpolation and expressions is bad practice
问题描述
来自文档:
<块引用>在表达式中嵌入插值标记
<块引用>注意: AngularJS 指令属性采用带有嵌入表达式的表达式或 插值标记.在表达式中嵌入插值标记被认为是不好的做法:
我正在寻找一个写得很好的规范答案,我可以为读者指出.
来自文档:
<块引用>为什么混合插值和表达式是不好的做法:
它增加了标记的复杂性
不能保证它适用于每个指令,因为插值本身就是一个指令.如果另一个指令在插值运行之前访问属性数据,它将获得原始插值标记而不是数据.
它会影响性能,因为插值会向范围添加另一个观察者.
From the Docs:
Embedding interpolation markup inside expressions
Note: AngularJS directive attributes take either expressions or interpolation markup with embedded expressions. It is considered bad practice to embed interpolation markup inside an expression:
I am looking for a well written canonical answer to which I can point readers.
From the Docs:
Why mixing interpolation and expressions is bad practice:
It increases the complexity of the markup
There is no guarantee that it works for every directive, because interpolation itself is a directive. If another directive accesses attribute data before interpolation has run, it will get the raw interpolation markup and not data.
It impacts performance, as interpolation adds another watcher to the scope.
这篇关于为什么混合插值和表达式是不好的做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!