必要なコントローラーへのメッセージブロードキャストを処理するために使用されるサービスがあります。
サービス:
.factory('mySharedService', function($rootScope) {
var sharedService = {};
sharedService.message = '';
sharedService.prepForBroadcast = function(msg) {
this.message = msg;
this.broadcastItem();
};
sharedService.broadcastItem = function() {
$rootScope.$broadcast('handleBroadcast');
};
return sharedService;
});
コントロール:
function AlertCtrl($scope, mySharedService) {
$scope.msgs = [];
$scope.$on('handleBroadcast', function() {
$scope.msgs.push(mySharedService.message);
});
$scope.closeAlert = function(index) {
$scope.msgs.splice(index, 1);
};
}
html:
<div ng-controller="AlertCtrl">
<alert ng-repeat="msg in msgs" type="msg.type" close="closeAlert($index)">{{msg.msg}}</alert>
</div>
HTMLスニペットをドロップすると、モーダルウィンドウにある場合を除いて、メッセージが期待どおりに表示されます。
私の質問は:ブロードキャストされたメッセージをモーダルウィンドウに表示するにはどうすればよいですか?
plnkr は次のとおりです: http://plnkr.co/edit/l6ohBYRBMftpfxiKXvLr?p=preview