我正在使用angular-modal-service库。我的逻辑是:当模式打开时,它运行一个函数 fromSomeService
和$rootScope.$broadcast
fromSomeService
到模式控制器,这样我就可以将资源从服务发送到我的模式控制器。但是,它不会触发。请帮我弄清楚我错过了什么。谢谢你。
**服务: **
angular.module('ng-laravel').service('SomeService', function($rootScope, Restangular, CacheFactory, $http) {
this.testFunction = function() {
console.log("from service");
$rootScope.$broadcast('event', {success:'success'});
};
}
**控制器: **
$scope.show = function(customer_id) {
ModalService.showModal({
templateUrl: 'modal.html',
inputs: {
customer_id: customer_id
},
scope: $scope,
controller: function($scope, close) {
$scope.customer_id = customer_id;
$scope.close = function(result) {
close(result, 500); // close, but give 500ms for bootstrap to animate
};
$scope.$on('event', function(event, data){
alert('yes');
console.log('from modal controller');
});
}
}).then(function(modal) {
SomeService.testFunction(customer_id, tour_id);
modal.element.modal();
modal.close.then(function(result) {
$scope.message = "You said " + result;
});
});
};
切换功能后它可以工作,但是......我如何将数据传递给模态?就像 ui-bs-modal 一样,他们有决心。