1. serviceName.getData(); 2. The url points to a text file on the local web server. Navigating from Browser to the file opens it with no problem.
On Friday, September 5, 2014 9:58:27 AM UTC-5, Thomas Murphy wrote: > > 1. What are you doing in the controller once you call > serviceName.getData()? > 2. What url are you calling in $http.get? If you're not calling anything, > you'll get no data. > > Best, > Thomas > > > On Fri, Sep 5, 2014 at 10:49 AM, mark goldin <[email protected] > <javascript:>> wrote: > >> I also found this code: >> function ($http, $q) { >> return { >> getData : function(){ >> var deferred = $q.defer(); >> var promise = $http.get(url).success(function (response) { >> deferred.resolve(response); >> }); >> // Return the promise to the controller >> return deferred.promise; >> } >> } >> >> and in controller to get data: serviceName.getData(); >> >> but I get no data. Can you please explain why is not working? >> >> Thanks >> >> >> On Friday, September 5, 2014 9:39:49 AM UTC-5, mark goldin wrote: >>> >>> Ok, I see how it works. >>> Another question. Is it possible to have just one function *MyTestService >>> *and run it like this? >>> <div ng-controller='*MyTestService *as vm'> >>> <p>the result from the service load:</p> >>> <pre>{{vm.data|json}}</pre> >>> </div> >>> >>> On Friday, September 5, 2014 9:28:42 AM UTC-5, mark goldin wrote: >>>> >>>> What vm.data shown in index.html would come from if I remove the >>>> TestMyService function? >>>> >>>> On Friday, September 5, 2014 1:32:11 AM UTC-5, Sander Elias wrote: >>>>> >>>>> Hi Mark, >>>>> >>>>> You mean something like this: http://plnkr.co/edit/ >>>>> 5cENSfOAhKJDI0iwe6ZV?p=preview >>>>> >>>>> Regards >>>>> Sander >>>>> >>>> -- >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> 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.
