ngBind、ngBindHtm 和 ngBindHtm 之间的区别Angular JS 中的 ngBindTemplate [英] Difference between ngBind, ngBindHtm & ngBindTemplate in Angular JS

查看:23
本文介绍了ngBind、ngBindHtm 和 ngBindHtm 之间的区别Angular JS 中的 ngBindTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Angular JS 的新手.

你们中的任何人都可以解释一下 ngBindngBindHtmngBindHtm 之间的区别吗?ngBindTemplateAngular JS 中有一个例子吗?

Can any one of you guys explain me the difference between ngBind,ngBindHtm & ngBindTemplate in Angular JS with an example?

推荐答案

ng-bind

ngBind 用于将指定 HTML 元素的文本内容替换为给定表达式的值.例如,如果您有一个如下所示的 html <b ng-bind="name"></b> 并在您的控制器中为 name 提供一个值 $scope.name= "约翰".这将导致 <b>John</b>.但是您不能使用多个值绑定到单个 html 元素中.例如

ng-bind

ngBind is used to replace the text content of the specified HTML element with the value of a given expression. For example if you have an html as follows <b ng-bind="name"></b> and in your controller give a value for name as $scope.name = "John". This will result in <b>John</b>. But you can't use multiple values to bind in a single html element. For example

$scope.first_name = "John";
$scope.second_name = "D";
<b ng-bind="first_name second_name"></b> 

这不会给出 <b>John D</b> 仅绑定 first_name 的结果.所以为了绑定多个值,我们可以使用 ng-bind-template

This will not give the result as <b>John D</b> only bind first_name. So for binding multiple values we can use ng-bind-template

 $scope.first_name = "John";
 $scope.second_name = "D";

<b ng-bind-template="{{first_name second_name}}"></b>

这导致 John D但是你不能在这两者中渲染一个 html 标签.对于渲染 html 模板,我们可以使用 ng-bind-html.

This results in <b>John D</b> But you can't render an html tag in this both. For rendering html template we can use ng-bind-html.

$scope.name = "<b>John</b>";
<div ng-bind-html="name"></div>

这将导致 John 而不是显示 <b>John</b> .这意味着它呈现 html 而不是显示 html 标签.

This will result in John instead of showing <b>John</b> . That means it renders the html instead of showing html tag.

点击此链接查看示例

这篇关于ngBind、ngBindHtm 和 ngBindHtm 之间的区别Angular JS 中的 ngBindTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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