Unable to get attribute from object in javascript but I can print it to the console when logging its parent. It does appears as being an ordinary object. Why cant i access _id?
The code below is in a function: $scope.create = function() { that gets called on submit of a form in my angular view:<form class="form-horizontal" data-ng-submit="create()" novalidate>
So heres the problem, in my function create:
console.log($scope.account);
var tmp=$scope.account;
console.log('id:' +tmp._id);
Gives me:
{"user":{"displayName":"David Karlsson","_id":"548217e5402b8b8c194d9c11"},"_id":"5483235cc0d8580000152f0b","__v":0,"created":"2014-12-06T15:40:12.682Z","amount":0,"interests":[{"rate":123,"date":"2014-12-30T23:00:00.000Z","_id":"5483235cc0d8580000152f0c"}],"desc":"","name":"Acount"}
id:undefined
Changing the post method did not help:
$scope.create = function() {
// Create new Income object
var copy = Object.assign({}, this.account);
console.log(copy);
}
Gives:
TypeError: undefined is not a function at Scope.$scope.create (localhost:3000/modules/incomes/controllers/incomes.client.controller.js:12:29) at localhost:3000/lib/angular/angular.js:10880:21 at callback (ocalhost:3000/lib/angular/angular.js:19237:17) at Scope.$eval (localhost:3000/lib/angular/angular.js:12788:28) at Scope.$apply (localhost:3000/lib/angular/angular.js:12886:23) at HTMLFormElement. (localhost:3000/lib/angular/angular.js:19242:23) at localhost:3000/lib/angular/angular.js:2853:10 at forEach (localhost:3000/lib/angular/angular.js:325:18) at HTMLFormElement.eventHandler (localhost:3000/lib/angular/angular.js:2852:5)