在我的应用程序中,我有一个非常简单的控制器,它的工作是显示消息:
angular.module("app.components.messages", ['ngSanitize'])
.controller("MessageBoxController", ['$scope', function($scope)
{
$scope.messageType = 'info';
$scope.hidden = true;
$scope.$on('message.error', function(event, message)
{
$scope.message = message;
$scope.messageType = 'error';
$scope.hidden = false;
});
$scope.$on('message.warning', function(event, message)
{
$scope.message = message;
$scope.messageType = 'warning';
$scope.hidden = false;
});
}]);然后消息框本身是非常直接的:
<div id="message-box" ng-controller="MessageBoxController"></div>我之所以使用ngSanitize,是因为有时我想在消息中添加链接。例如,在另一个控制器中,我可以这样做:
$rootScope.$broadcast('message.warning', 'You are about to download ' + file.name + ' which is ' + file.size + '. Your current quota is ' + user.quotaRemaining + ' click <a href="' + url + '">here</a> to confirm.'); 这是可行的,并显示链接和所有东西。但是,在这种情况下,在用户单击链接之后,我希望它启动另一个函数来更新用户的配额信息。我天真地尝试在我的标签上点击ng键,但结果是ngSanitize过滤掉了某些属性,所以这是行不通的。
在点击消息中的链接之后,我怎样才能让事情发生呢?我不一定非得使用ngSanitize,我只是使用它,因为它看起来很方便。
发布于 2014-12-04 08:25:34
Here解决了类似的问题。只需重命名指令并传递给您message的指令即可。例如:
<div message="message"></div>https://stackoverflow.com/questions/27288918
复制相似问题