*UPDATE: *I simplified it so it doesn't use the factory/service. But when
I try to output the data it's empty. Please see below.
(Tried using both of these:)
$scope.models = [];
var list = {};
$scope.loadModels = function () {
var httpRequest =
$http.post('AngularWithWebServices.aspx/FetchJVCModelsB', { data: {} })
.success(function (data, status, headers, config) {
$scope.models = data;
list = data;
}).error(function (data, status, headers, config) {
console.log('Error:', data);
});
};
$scope.loadModels();
console.log($scope.models);
console.log(list);
//console.log(list.typeOf());
$.each(list.d, function (i, val) {
console.log(val.ModelNum);
});
On Wednesday, June 18, 2014 6:04:38 PM UTC-5, [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.