gpt4 book ai didi

angularjs - Angular JS 中 ngBind、ngBindHtm 和 ngBindTemplate 之间的区别

转载 作者:行者123 更新时间:2023-12-03 11:33:54 25 4
gpt4 key购买 nike

关闭。这个问题需要更多 focused .它目前不接受答案。












想改进这个问题?更新问题,使其仅关注一个问题 editing this post .

8年前关闭。




Improve this question




我是 Angular JS 的新手.

有谁能解释一下ngBind之间的区别吗? , ngBindHtm & ngBindTemplateAngular JS举个例子?

最佳答案

ng-绑定(bind)

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

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

这不会给出 <b>John D</b> 的结果 只绑定(bind)名字 .因此,对于绑定(bind)多个值,我们可以使用 ng-bind-template
ng-绑定(bind)模板
 $scope.first_name = "John";
$scope.second_name = "D";

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

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

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

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

点击此链接查看 example

关于angularjs - Angular JS 中 ngBind、ngBindHtm 和 ngBindTemplate 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com