gpt4 book ai didi

javascript - AngularJS 中是否有 ng-bind-html-unsafe 的回调

转载 作者:行者123 更新时间:2023-11-30 05:39:29 25 4
gpt4 key购买 nike

我想删除一些由此带入 DOM 的元素...

<div ng-bind-html-unsafe="whatever"></div>

我编写了一个将删除元素的函数,但我需要一种在 ng-bind-html-unsafe 完成后触发该函数的方法。是否有针对 ng-bind-html-unsafe 的回调或更好的方法?

最佳答案

ng-bind-html-unsafe 已从当前版本 (1.2+) 的 Angular 中删除。我建议在新版本的 Angular 中使用 $sanitize 服务。您需要包含 sanitize 库并将其添加到您的模块中。

这样你就可以在清理操作完成后做任何你想做的事而不用担心回调。

快速而肮脏的实现:

<!doctype html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js"></script>
<script src="libs/angular/angular-sanitize.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="myController">
<div>{{sanitized}}</div>
</div>
<script>
angular.module('myApp', ['ngSanitize'])
.controller('myController', ['$scope', '$sanitize', function($scope, $sanitize) {
$scope.sanitized = $sanitize('someTextFromSomeSource');
// Do whatever you want here with the cleaned up text
}])
</script>
</body>
</html>

关于javascript - AngularJS 中是否有 ng-bind-html-unsafe 的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21589943/

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