Reputation: 4136
I'm trying to trigger an action defined in one controller from second one. I've gone through this question, but I can't see what I am doing wrong. Here goes the code:
window.cartApp = angular.module 'cartApp', ['pascalprecht.translate', 'directives', 'cartServices',
'angular-click-outside']
class CartCtrl
constructor: (@$scope, @$http, @$timeout, @$filter, PriceOption, EnableMealsService, CookiesService) ->
@$scope.cartItems = {'meals': [], 'submeals': []}
@$scope.Math = window.Math;
_scope = @$scope
_http = @$http
window.cartApp.config(window.translate)
@$scope.$on('triggerGetQuote', () -> console.log('getting quote'))
class IndexCtrl
constructor: (@$scope, @$rootScope, @$http, CookiesService) ->
_scope = @$scope
_rootScope = @$rootScope
_http = @$http
@$scope.getLocation = () ->
console.log('Before broadcast of triggerGetQuote')
_scope.$broadcast('triggerGetQuote')
CartCtrl.$inject = ['$scope', '$http', '$timeout', '$filter', 'PriceOption', 'EnableMealsService', 'CookiesService']
IndexCtrl.$inject = ['$scope', '$rootScope', '$http', 'CookiesService']
window.cartApp.controller 'CartCtrl', CartCtrl
window.cartApp.controller 'IndexCtrl', IndexCtrl
So I'm expecting to get both events logged in my console, however, only the first one is triggered:
Before broadcast of triggerGetQuote
Upvotes: 0
Views: 35