如何在 angular-ui bootstrap 警报中包含链接?
试图:
Plunker Example
HTML
<div ng-controller="AlertDemoCtrl">
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
<button class='btn' ng-click="addAlert()">Add Alert</button>
</div>
脚本
function AlertDemoCtrl($scope) {
$scope.alerts = [
{ type: 'error', msg: 'Oh snap! Change a few things up and try submitting again.' },
{ type: 'success', msg: '<a href="">Well done!</a> You successfully read this important alert message.' }
];
$scope.addAlert = function() {
$scope.alerts.push({msg: "Another alert!"});
};
$scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1);
};
}
最佳答案
在 AngularJS 表达式中嵌入 HTML 标记通常不是最好的方法,因为这样你将无法评估 AngularJS 指令。
无论如何,回到你的问题 - 有很多方法可以解决你的问题。如果您刚刚显示链接,最简单的方法是使用 ng-bind-html
指令( http://docs.angularjs.org/api/ngSanitize.directive:ngBindHtml ):
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">
<span ng-bind-html="alert.msg"></span>
</alert>
工作电话:http://plnkr.co/edit/Ftab0xtcelXcHSZbFRxs?p=preview
关于angularjs - 在 angular-ui bootstrap 警报中包含链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17475728/