ngBind,ngBindHtm与放大器之间的差异; ngBindTemplate在角JS [英] Difference between ngBind, ngBindHtm & ngBindTemplate in Angular JS
问题描述
我是新来的角JS
。
你们中的任何一个可以解释我的区别 ngBind
, ngBindHtm
&安培; ngBindTemplate
在角JS
用一个例子?
Can any one of you guys explain me the difference between ngBind
,ngBindHtm
& ngBindTemplate
in Angular JS
with an example?
推荐答案
ngBind用于替换指定的HTML元素的与给定的前pression的值的文本内容。例如,如果你有一个HTML如下:< b NG绑定=名与GT;< / B>
,并在你的控制器提供一个值,名称为 $ scope.name =约翰
。这将导致< B>约翰和LT; / 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>
这不会给结果为&LT; B&GT;约翰·D&LT; / B&GT;
只能绑定FIRST_NAME 。因此,对于绑定多个值,我们可以使用 NG-绑定模板
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>
这导致的 &LT; B&GT;约翰·D&LT; / B&GT;
但是,你不能同时呈现在这个HTML标记。对于渲染HTML模板,我们可以使用NG-绑定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>
这将导致 约翰 ,而不是显示&LT; B&GT;约翰&LT; / B&GT;
。这意味着它呈现HTML而不是显示HTML标签。
This will result in John instead of showing <b>John</b>
. That means it renders the html instead of showing html tag.
点击此链接可查看
Click this link to view example
这篇关于ngBind,ngBindHtm与放大器之间的差异; ngBindTemplate在角JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!