I have a following case. A ngGrid which labels are read from asynchronous
Service so labels are read dynamically and tey are not hard coded.
I have gathered all asynchronous calls fetching label data into $q.all and
then fetching their data in the .then part.
But in some cases labels are not shown into ngGrid so this must be
something to do with asynchronous calls and ngGrid synchronizing.
How should I code $q.all and it async calls so that I would be sure that
when they are set into ngGrid they contain proper labels?
Br Dan
var deferred = $q.defer();
myService.getAttribute(key, function(label) {
var result = label;
deferred.resolve(result);
});
return deferred.promise;
};
/** Fetching labels asynchronously */
$q.all(
[ getLabelTxt('Form.Field1'),
getLabelTxt('Form.Field2'),
getLabelTxt('Form.Field3') ]).then(
function(data) {
$scope.setColDefs(data);
});
$scope.gridOptions = {
data : 'dataModel',
enableColumnResize : true,
selectedItems : [],
columnDefs : [
{
field : 'Field1',
displayName : ''
}, {
field : 'Field2',
displayName : ''
}, {
field : 'Field3',
displayName : ''
} ]
};
/** Setting values fetched from Asynch service */
$scope.setColDefs = function(rows) {
for (var i = 0; i < rows.length; i++) {
if ($scope.gridOptions.columnDefs[i] !== undefined) {
$scope.gridOptions.columnDefs[i].displayName = rows[i];
}
}
}
--
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.