I'm not 100% sure what you're trying to do here, but I have some
observations. Maybe they're useful, maybe not.

1) $scope.jvcModels isn't an array, but a promise. You need to do something
like
myDataService.FetchJVCModels().then(function(data){$scope.jvcModels=data;
/* do what you will with jvcModels here*/});, more or less.

2) You're doing an unnecessary $q.all call - $q.all returns a promise for
an array when given an array of promises, but $http.post is just a single
item. At best that's weird, at worst it won't work. Never tried it myself.
If you must, i'd do $q.all([$http...])

3) You don't have a .catch call at the end of your promise chain, so errors
from $http will just evaporate. I'd suggest returning
promise.catch(function(err){console.log('ERRORRR!');}) instead of just the
promise. It will still be a promise that will still resolve to the data,
but you'll also catch errors. That said, I usually don't put a .catch in
service fetch calls, but rather manually attach them to the end of all my
promise chains.

e


On Wed, Jun 18, 2014 at 4:04 PM, <[email protected]> wrote:

> var data  =
> [{"ModelNum":"KD-A305","Year":"2008","Price":129.95,"Pic":"kd-a305prodPic3.jpg"},{"ModelNum":"KD-A315","Year":"2010","Price":129.95,"Pic":"KD-A315prodPic1.jpg"}]
>
> When I use this variable everything works in Angular.
>
>
> But when I try stuffing it in a $scope:
>
> var data = JSON.parse($scope.jvcModels);
>
> Error: JSON.parse: unexpected character at line 1 column 2 of the JSON data
>
>
> Service
>
> $scope.jvcModels = myDataService.FetchJVCModels();
>
> Factory
>
> app.factory('myDataService', function ($http,$q) {
>
>     return {
>
>         FetchJVCModels: function () {
>
>             //var promise =
> $http.post('AngularWithWebServices.aspx/FetchJVCModels', { data: {}
> }).then(function (response) {
>             var promise =
> $q.all($http.post('AngularWithWebServices.aspx/FetchJVCModelsB', { data: {}
> }).then(function (response) {
>
>                 //console.log(response);
>
>                 return response.data;
>             }));
>
>             return promise;
>
>         },
>
> --
> 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.

Reply via email to