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

Binding a html content in scope variable without using ng-bind-html

本文关键字:变量 绑定 内容 html 范围 情况下 ng-bind-html      更新时间:2023-09-26

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

<div ng-controller="dataController">{{test}}</div>
$scope.test = "<div>Html content</div>"

这是您要查找的:

小提琴

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

视图

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