hello, I am trying to figure out how to properly use $broadcast to
communicate with child controllers during the parent controller startup .
That is to say, when I try to $broadcast from the parent controller on
startup it seems the children are not listening yet.
If I put the $brodcast into a setTimeout then it works.
I seek a better way.
Is there an even that I can listen for that will tell me that all my
children have finished instantiating?
Is there a $function I can call to queue a function to execute when all my
children have finished instantiating?
And while I'm asking questions -- where is the list of events that Angular
emits during normal operations? Or is it not right to depend on those ?
thanks very much for your time
al
---------- parent controller ------------
angular.module('paperApp')
.controller('ChartCtrl', function ($scope, $filter, $routeParams,
paperData ) {
// this does not work, the child never 'hears' the event
paperData.getData($routeParams, function(data) {
console.log('ChartCtrl:'+$scope.$id,'broadcasting: newData
event');
$scope.$broadcast('newData', data);
});
// this does work, the child 'hears' the event
paperData.getData($routeParams, function(data) {
setTimeout(function(){
console.log('ChartCtrl:'+$scope.$id,'broadcasting: newData
event');
$scope.$broadcast('newData', data);
},250);
});
});
---------- a child controller -----------
angular.module('paperApp')
.controller('GraphCtrl', function ($scope) {
$scope.$on('newData', function(event, data) {
console.log('GraphCtrl:'+$scope.$id,event); });
});
---------- my html ------------
<div class='pageWrapper' ng-controller="ChartCtrl">
<div class="leftColumn">
<div class="chartWrapper" ng-controller="GraphCtrl">
<div google-chart chart="chartRightData" class="chartRight
ng-isolate-scope" on-ready="chartReady()"></div>
</div>
<div class="tableSummary" ng-controller="SummaryCtrl">
<table dt-table="{ bAutoWidth: false, deferRender: true, pageLength: 5,
paging: false, ordering: false, info: false, filter: false }"
aa-data="tableSummaryData"
columns="[
{ width: '25%', sClass: 'dt-cell-right' },
{ width: '25%', sClass: 'dt-cell-right' },
{ width: '25%', sClass: 'dt-cell-right' },
{ width: '25%', sClass: 'dt-cell-right' }
]"
>
<thead><tr><th>Rolls</th><th>Current</th><th>Last</th><th>Change</th></tr></thead>
</table>
</div>
</div>
<div class="rightColumn">
<div class="tableDetail" ng-controller="PointsCtrl">
<table dt-table="{ scrollY: '550px', scrollCollapse: true, bAutoWidth:
false, deferRender: true, pageLength: 365, paging: false, ordering: true,
info: false, filter: false }"
aa-data="tableDetailData"
order="[[ 0, 'asc' ]]"
columns="[
{ width: '25%', sClass: 'dt-cell-right', sType: 'date' },
{ width: '25%', sClass: 'dt-cell-right' },
{ width: '25%', sClass: 'dt-cell-right' },
{ width: '25%', sClass: 'dt-cell-right' }
]"
>
<thead><tr><th>Date</th><th>Inches Printed</th><th>Feet
Printed</th><th>Rolls Printed</th></tr></thead>
</table>
</div>
</div>
</div>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.