为什么混合插值和表达式是不好的做法 [英] Why mixing interpolation and expressions is bad practice

查看:72
本文介绍了为什么混合插值和表达式是不好的做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档中:

在表达式内部嵌入插值标记

注意:AngularJS指令属性采用带嵌入式表达式的表达式插值标记.将插值标记嵌入到表达式内被认为是不好的做法:

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:

AngularJS开发人员指南-插值

我正在寻找一个写得很好的规范答案,可以指向读者.

I am looking for a well written canonical answer to which I can point readers.

推荐答案

来自文档:

为什么混合插值和表达式是不好的做法:

  • 它增加了标记的复杂性

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.

AngularJS开发人员指南-插值

这篇关于为什么混合插值和表达式是不好的做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆