我正在使用angular-modal-service库。我的逻辑是:当模式打开时,它将SomeService
和$rootScope.$broadcast
从SomeService
的功能运行到模态控制器,这样我可以将资源从服务发送到我的模态控制器。但是,它不会触发。请帮我弄清楚我错过了什么。谢谢。angularjs模式服务广播和发布
**服务:**
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一样,他们已经解决了。
是否缺少'返回此;'你的服务? –
@PrashantGhimire没有必要从服务中返回'this' ..''service'会隐式返回'this'(context)的功能 –
很高兴知道! @PankajParkar;) –