加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – AngBind中ngBind,ngBindHtm和ngBindTemplate之间的

发布时间:2020-12-17 08:08:20 所属栏目:安全 来源:网络整理
导读:我是Angular JS的新手。 你们中有谁能解释一下ngBind,ngBindHtm ngBindTemplate在Angular JS中有一个例子? NG-绑定 ngBind用于使用给定表达式的值替换指定HTML元素的文本内容。例如,如果你有一个html,如下所示 b ng-bind =“name” / b并在您的控制器中
我是Angular JS的新手。

你们中有谁能解释一下ngBind,ngBindHtm& ngBindTemplate在Angular JS中有一个例子?

NG-绑定

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

$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

NG-绑定模板

$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绑定,HTML

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

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

点击此链接查看example

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读