The goal is to get the data during the initialization phase of the app, and
use it to build out subsequent pages. I thought I could use a service to
get the data, and inject it into my directive, but I'm only getting
undefined. As best I can tell, the directive is getting parsed before the
data is returned. If that's true, what can I do about it?
What is the right way to ajax in some data and make it available to the
whole app?
Here's what I thought would work:
/* service */
myapp.service('pages', function($http)
{
var self = this;
$http.jsonp('http://...?callback=JSON_CALLBACK', self)
.success(function(data)
{
return self.pages = data;
});
return self.pages;
});
/* directive */
mydirectives.directive('ngPg2', ['$controller', 'pages', directive2]);
function directive2($controller, pages)
{
console.log('directive2()');
window.myp = pages.pages; //this works and data is available.
console.log(pages.pages); //undefined
}
--
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/groups/opt_out.