gpt4 book ai didi

javascript - 在不使用 ng-bind-html 的情况下在范围变量中绑定(bind) html 内容

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

如何在 angularjs 中使用范围变量(不使用 ng-bind-html-unsafe)绑定(bind) html 内容

<div ng-controller="dataController">{{test}}</div>

$scope.test = "<div>Html content</div>"

最佳答案

这就是你要找的:

Fiddle

function dataController($scope,$sce){
$scope.test = "<div>Html content</div>";
$scope.test = $sce.trustAsHtml($scope.test);
}

查看

<div ng-bind-html="test"></div>

关于javascript - 在不使用 ng-bind-html 的情况下在范围变量中绑定(bind) html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22885535/

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