javascript - ngBindTemplate 和 ngBind 有什么区别?

标签 javascript angularjs

根据文档:

The ngBind attribute tells Angular to replace the text content of the specified HTML element with the value of a given expression, and to update the text content when the value of that expression changes.

The ngBindTemplate directive specifies that the element text content should be replaced with the interpolation of the template in the ngBindTemplate attribute. Unlike ngBind, the ngBindTemplate can contain multiple {{ }} expressions. This directive is needed since some HTML elements (such as TITLE and OPTION) cannot contain SPAN elements.

我的解释是 ngBindTemplate 可以完成 ngBind 所做的一切,甚至更多。那么为什么我们还要有 ngBind 呢?

最佳答案

正如您在 sources 中看到的那样,ngBindTemplate涉及$interpolate服务,其中:

Compiles a string with markup into an interpolation function. This service is used by the HTML $compile service for data binding.

关于javascript - ngBindTemplate 和 ngBind 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20962112/

相关文章:

javascript - 创建一个 jQuery 垂直滚动循环

javascript - 三栏布局的屏幕阅读器如何自定义阅读顺序?

javascript - 用于匹配多个属性的 Angular 指令

javascript - 清除数组后不会更新 ng-options 绑定(bind)变量

javascript - 从 html5 <video> 标签中添加或删除 controls 属性

javascript - 单独进入那个div时显示<div>

javascript - 是否可以在 es6 模板字符串中进行评论?

javascript - 双击使表格单元格可编辑-Angularjs

javascript - jQuery 的更改方法在这里做什么(如果有的话)?

arrays - Angular : how can i filter nested object properties?