我有一个警告如下:
$scope.addAlert('danger', $sce.trustAsHtml('Invalid Alias Name: Certain
limitations apply to alias naming. <a href="http://google.com/">Please refer
to the documentation</a>'));我将其绑定到html页面如下:
<uib-alert ng-repeat="alert in alerts" type="{{alert.type}}"
close="closeAlert($index, alerts)" dismiss-on-timeout="2500">
<span ng-bind-html="alert.msg"></span>
</uib-alert>因此,实际输出:
Error: Invalid Alias Name: Certain
limitations apply to alias naming. '<a href="http://google.com/">Please
refer to the documentation</a>'预期输出:错误:别名名称无效:某些限制适用于别名命名。'请参阅文件‘
有人能帮忙吗?我不知道我错过了什么!
谢谢!
发布于 2018-03-26 13:33:48
您是否可以尝试下面的代码,也可以为给定的示例场景检查这个工作的柱塞。
模板:
<body ng-controller="MainCtrl">
<div ng-repeat="alert in alerts">
<h4 ng-bind="alert.title"></h4>
<span ng-bind-html="alert.msg | formatContent"></span>
</div>
</body>控制器:
app.controller('MainCtrl', function($scope, $sce) {
$scope.alerts=[];
$scope.addAlert=function(title, msg){
$scope.alerts.push({title: title, msg: msg});
}
$scope.addAlert('danger', 'Invalid Alias Name: Certain limitations apply to alias naming. <a href="http://google.com/">Please referto the documentation</a>');
});
app.filter('formatContent', ['$sce', function($sce){
return function(input){
return $sce.trustAsHtml(input);
}
}]);我已经更新了我的答案,用过滤器实现它,如上面的代码所示,还检查了正在使用过滤器实现的这个柱塞连杆。
https://stackoverflow.com/questions/49492130
复制相似问题