javascript - AngularJS: objects, arrays, JSON, API issues -


create:

i using $scope.services storing list of services. array of objects:

$scope.services = [{     title           : undefined,     quantity        : undefined,     priceperunit    : undefined,     pricecalculated : undefined,     order           : undefined          }]; 

i can push object array.

$scope.services.push({      title           : undefined,     quantity        : undefined,     priceperunit    : undefined,     pricecalculated : undefined,     order           : undefined }); 

so far, good. using object model within angular, show content.

update:

i calling api , getting json in format:

{     somedata: "some data",     services: {         0: {             id: 101,             offer_id: 101,             title: "some title",             ...         },         1: {             ...         }     } } 

appending received data $scope.services = data.services , when calling $scope.services.push console error

typeerror: $scope.services.push not function. 

what wrong? json/array issue? never got bottom of this, theory knowledge appreciated well. thank in advance.

because services not array, (push defined arrays: array.prototype.push()) need construct proper array response.

var servicesarray = []; object.keys(data.services).foreach(function (key) {    servicesarray.push(data.services[key]); });  $scope.services = servicesarray; 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -