Push is not function Angularjs error -
$scope.post1 = angular.fromjson(window.localstorage['like'] || '{}'); var ={ id:''+id }; $scope.post1.push(like); window.localstorage['like'] = angular.tojson( $scope.post1);
when run code gives $scope.post1.push not function..how solve problem?
there no push() function in javascript object or string. array has it.
maybe instead:
$scope.post1.like = { id: '' + id };
see https://docs.angularjs.org/api/ng/function/angular.fromjson more information angular.fromjson()
return type.
edit:
it seems misread something. try this:
http://plnkr.co/edit/pxnul5c9fbknhxhqzjef
if want create array of object, should pass array angular.fromjson()
Comments
Post a Comment