I have a piece of code that needs to be invoked after execution of some other code. i'm using broadcast
for this. I need to invoke the same code from 2 different places. Now that is not working for me.
My code is
Broadcast 1
scope.$broadcast('selOrdLine', ordline);
On
scope.$on('selOrdLine', function (event, args) {
// some code here
})
I need to invoke this code from some other place also
so I put scope.$broadcast('selOrdLine', ordline);
there also. But it is returning error.
Edit
The second time when I use broadcast
I'm making the ordline
data using the angular.forEach
loop. so I'm using $q
for running the broadcast only after the data is ready like this
$q.all(orderline).then(function () {
$scope.$broadcast('selOrdLine', orderline);
});
The error is, the broadcast
is invoked multiple times. But as I use $q
it should run only after the orderline data is set, right ?