This really help me to understand better how promise works.

Thanks again

Le vendredi 1 mai 2015 23:58:56 UTC+2, Greg a écrit :
>
> Hi
>
> I have a service.js file:
>
> app.service('SharedData', function($http) {
>
> service = {};
>
> $http.get('config.json') 
>     .success (function(data) {  
>         service.siteID = data._id; 
>         console.log(service.siteId); // return 12345
>           
>         $http.get('/api/sites/' + service.siteID)
>             .success(function(site) {
>                 service.template = site.template;
>                 console.log(service.template); // return myTemplate
>             })
>     })
>
> return service
> })
>
> In controller.js I want to use data from the service
>
> app.controller('pagesController', function(SharedData, $scope, $http) {
>  console.log(service); // return objet with all values
> console.log('Site ID is ' + service.siteID); // return undefined  !!!!!
> console.log('Template is ' + service.template); // return undefined !!!!!
>  $http.get('/api/sites/' + service.siteID) // service.siteID comes from 
> app.services.js
>  ...
> });
>
>  console.log(service) return an object with siteID: '12345' and template: 
> 'myTemplate'
>
> BUT
>
> console.log(service.siteID) & console.log(service.template) return 
> undefined 
>
> Any help would be appreciated
>
> Regards
> Greg
>
>

-- 
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.

Reply via email to