Angular の を使用しようとして$broadcast
、テストして文字列 'hi' を使用し、兄弟コントローラーでそれを監視すると、次のように正常に動作します。
//first controller
app.controller('colourKeyCtrl', colourKeyCtrl);
function colourKeyCtrl($scope, $timeout, patents, patentPhasesService) {
vm.$onInit = function() {
$scope.$broadcast('hi');
}
}
//second controller
app.controller('graphDonutCtrl', graphDonutCtrl);
function graphDonutCtrl($scope, patents, patentPhasesService, $timeout) {
$scope.$on('hi', function(event, opt){
alert('hello there')
})
}
文字列を などの別のものに変更するとすぐに、2 番目のコントローラーでメソッドphaseChange
を呼び出すことができません。$on
理由がわからない。メソッドをラップしようとし$broadcast
ました$timeout
が、問題は解決しませんでした。
質問
間違った方法で使用$broadcast
していますか、それとも構文が間違っていますか?
.state('dashboard', {
url: '/dashboard',
views: {
'@': {
templateUrl: 'p3sweb/app/components/dashboard/views/dashboard.htm',
controller: 'dashboardCtrl',
controllerAs: '$ctrl'
},
'colourkeywidget@dashboard': {
templateUrl: 'p3sweb/app/components/dashboard/views/ui-views/colour-key-widget.htm',
controller: 'colourKeyCtrl',
controllerAs: '$ctrl'
},
'graphdonutwidget@dashboard': {
controller: 'graphDonutCtrl',
controllerAs: '$ctrl',
templateUrl: 'p3sweb/app/components/dashboard/views/ui-views/graph-donut-widget.htm',
}
}
})