我正在使用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;) –