以下是我的代码示例,如果我删除了 ng-bind-html 那么 div 正在工作,如果没有失败,请给我一个答案
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular-sanitize.js"></script>
<script>
var app = angular.module('myApp', ['ngSanitize']);
app.controller('CartController', function($scope) {
$scope.title = "<p>hello world</p>";
$scope.test = "How are you..!How are you..!How are you..!";
});
</script>
<body ng-app="myApp" >
<div ng-controller="CartController">
<label ng-bind-html=title>
<div>{{test}}</div>
</label>
</div>
</body>
</html>
最佳答案
您需要使用 $sce.trustAsHtml
将 $sce
注入(inject) Controller :
app.controller('CartController', function($scope, $sce) {
$scope.title = $sce.trustAsHtml("<p>hello world</p>");
$scope.test = "How are you..!How are you..!How are you..!";
});
当然,HTML label
将完全被 $scope.title
取代,您将看不到 {{test}}
不再是
关于javascript - 如果父标签包含 ng-bind-html 指令,则没有 html 标签起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33567927/