You can do this in link- basically
xhrHitReturningAPromise().then(function(data)) {
//process data and update options
}).catch(function(err) {//don't forget to catch errors!})
You can also do a conditional thing, like set a loading to true, and then
on promise resolution set loading to false. Then you can do an
ng-show="loading" on your loading spinner kinda thing. Otherwise there's a
chance the user will see an empty set of options before they get to see the
stuff loaded from the backend hit. Which can be good (if you're querying in
response to input) or bad (if you're just prepopulating a field they expect
ASAP and doesn't need to respond to user actions inside the widget).
Almost always you can do things in link, it's only when you're directly
adding and subtracting things on the DOM that you do it in compile. So as
long as your options are in an ng-repeat, you're golden (the ng-repeat
handles the compile stuff).
e
On Sun, Jun 1, 2014 at 10:48 AM, Iain Duncan <[email protected]>
wrote:
> Hi, I'm making a custom select widget directive for some back end
> integration. It gets the options values from a rest xhr hit.
>
> I'm confused from reading the docs as to whether this xhr query and
> options population stage should happen in compile, preLink, or postLink.
> Any tips appreciated!
>
> iain
>
> --
> 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.
>
--
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.