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

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

问题描述

来自文档:

<块引用>

在表达式中嵌入插值标记

<块引用>

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

AngularJS 开发者指南 - 插值

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

解决方案

来自文档:

<块引用>

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

  • 它增加了标记的复杂性

  • 不能保证它适用于每个指令,因为插值本身就是一个指令.如果另一个指令在插值运行之前访问属性数据,它将获得原始插值标记而不是数据.

  • 它会影响性能,因为插值会向范围添加另一个观察者.

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:

AngularJS Developer Guide - Interpolation

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.

AngularJS Developer Guide - Interpolation

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

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