Reputation: 7123
I have $broadcast
event its working from parent controller but i don't see object coming in child controller i am not sure what i am implementing wrong.
How can i achieve this task using angularJs event ?
parentCtrl.js
$scope.$broadcast('assessmentData',$scope.RiskAssessDTO);
childCtrl.js
if ($stateParams.assessmentId) {
$scope.$on('assessmentData', function(s, assessmentData) {
var assessmentData = assessmentData;
console.log('assessmentData', assessmentData);
});
}
Upvotes: 0
Views: 36
Reputation: 340
If you want to use $broadcast you should use $rootScope.
$scope.startScanner = function() {
$rootScope.$broadcast('scanner-started');
}
And then to receive, use the $scope of your controller:
$scope.$on('scanner-started', function(event, args) {
// do what you want to do
});
https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$on
Regards,
Upvotes: 2