필요로하는 컨트롤러에 메시지 브로드 캐스팅을 처리하는 데 사용되는 서비스가 있습니다.Angular JS는 모달 창을 포함하여 여러보기에 메시지를 전송합니다.
서비스 :
가.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;
});
CNTL :
이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이
hmmmmmm, 그래서 메시지가 방송 된 후에 모달이 터지면 모달에 메시지 세트가 생깁니 까? – user2762149
ModalDemoCtrl에 msgs 목록을 넣고 (항목과 마찬가지로) 모달에 전달하십시오. 새 메시지가 목록 (예 : 비동기 작업)에 푸시 될 때마다 모달 메시지가 열려 있으면 해당 메시지가 모달로 표시됩니다 (그렇지 않으면 존재하지 않을 수도 있음). –