I have a page that has multiple instances of a given controller, all of
which need similar data. Their instantiation looks sort of like this:
<div ng-repeat="noteType in noteTypes" ng-controller="NoteController"
ng-init="init('note.noteTypeID')">
blah blah blah
</div>
Initially, I had them all calling a service along these lines
.controller('NoteController', ['$scope', '$log', '$sce', 'Utility',
function($scope, $log, $sce, Utility){
Utility.getList().success(
function(shortcutCategory) {
...init some stuff here...
});
}]);
where the service calls an https request for some data. Now that I'm using
multiples of this controller in the page, this seems dumb. I'm guessing
the best way to do this would be to populate something in the service
itself with the 'getList' array, and just let the controllers access that
array. Thus preventing the multiple, unnecessary calls.
Two Questions:
1) First one is about timing. The controllers really need that data to be
available before some internal initialization. I'm not sure how to handle
the timing of that. Should the service broadcast an event after it loads
up the 'getList' data?
2) Is my ng-init on the controller line an okay way to handle passing
instance specific data to each controller?
Thanks!
--
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.