gpt4 book ai didi

angularjs - 在 angular-ui bootstrap 警报中包含链接?

转载 作者:行者123 更新时间:2023-12-04 09:31:32 24 4
gpt4 key购买 nike

如何在 angular-ui bootstrap 警报中包含链接?

试图:

alert

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/

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