我有一個按鈕,其觸發的自定義模態(I所使用的模態從這裏http://codepen.io/m-e-conroy/pen/ALsdF)共享服務中AngularJS
按鈕駐留在MainController
控制器。
MainController
app.controller('MainController', function($scope, sharedService) {
$dialogs.create('dialog.html', 'SecondController',
{}, {key: false, back: 'static'});
// Start broadcast
sharedService.prepForBroadcast('Hello AngularJS');
});
SecondController
app.controller('SecondController', function($scope, sharedService) {
// This piece of code doesn't get called.
$scope.$on('handleBroadcast', function() {
console.log('received broadcast');
});
});
sharedService
app.factory('sharedService', function($rootScope) {
var data = {message: ''};
data.prepForBroadcast = function(message) {
this.message = message;
$rootScope.$broadcast('handleBroadcast');
};
return data;
});
我的問題是
謝謝。但它仍然不起作用.. – sc1013