You could always ng-hide your directive until the asynch request is
resolved.
something like:
your directive:
...
link: function(s,e,a){
s.data_not_loaded = true;
},
template: '<div ng-hide="data_not_loaded">...</div>',
controller: function($scope, $element, $attrs) {
$scope.newCust = custFactory.createCustomer().then(function(data) {
// resolve promise from createCustomer
$scope.data_not_loaded = false;
}, function(data) {
// reject promise i.e. error
}
}
--Aleck
On Sunday, March 16, 2014 10:32:48 AM UTC-4, MattB wrote:
>
> I have a custFactory service with a method called createCustomer that
> creates a customer model. This method uses data fetched from the server to
> initialize the customer model. I would like for the createCustomer method
> to be synchronous, so as to make the method easier to work with. Of course
> the method used to fetch data is asynchronous. I would like the method to
> look like this:
>
> var newCust = custFactory.createCustomer();
>
> I am aware of the resolve property used in routing, but I may want to use
> this service in a directive, in which case there is no resolve mechanism to
> ensure initialization.
>
> Are there any strategies for turning a method that has an asynchronous
> dependency into a synchronous method call? Or is it just a fact of life
> that once you have introduced an async dependency into a method that that
> method needs to propagate the asynchronicity (via a promise or callback).
>
> Sincerely,
>
> MB
>
--
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.