I'm having difficulty calling a function in a child controller in an ng-view from my parent controller.
currently my html has something along the lines of
<body ng-app="myApp" ng-controller="bodyController as bc" ng-init="bc.init()">
<ng-view><ng-view>
</body>
My JS has 2 controllers, the body controller and the view controller. I want to call a function from the view controller in the body controller but my $on and $broadcast functions are coming up as undefined and not running.
app.controller('bodyController', bodyController);
app.controller('viewController', viewController);
function bodyController(){
var vm = this;
vm.init = function(){
vm.$broadcast('load')
}
function viewController(){
var vm = this;
vm.$on('load', functionToCall)
}
I thought the issue might be that the view controller wasn't loaded yet so i couldnt call a function from it. so I instead tried emitting a signal from the view controller on its ng-init that the parent bodyController would hear and then broadcast back a new signal so that the function ran but that wasn't working either. I've tried searching through stack overflow for a while now and either can't find a relevant answer or the answers are over my head. I'd appreciate any help greatly.