javascript - Angular: trying to submit coordinates array -


i'm developing geolocation api, , i'm having hard time submitting 2 coordinates merged array. in mongoose schema, have this:

geolocation: {   type: { type: string, default:"point" },   coordinates: [number],  }, 

in index.html, have input

 input ng-model='values[0]' type='text' input ng-model='values[1]'   type='text'   

in controller, i'm trying

function maincontroller($scope, $http) {         $scope.formdata = {};         $scope.values=[];  $scope.createlocation = function() {         $scope.formdata.geolocation.coordinates = new array(2);         $scope.formdata.geolocation.coordinates.push({             0: $scope.values[0],             1: $scope.values[1]         });         $http.post('/api/places/:location', $scope.formdata)             .success(function(data) {                 $scope.formdata = {}; // clear form our user ready enter                                        $scope.locations = data;                 console.log(data);             }) 

however, when submit, error

 cannot set property 'coordinates' of undefined 

what doing wrong?

as pointed out @neil-lunn, error in frontend, ,

$scope.formdata.geolocation = { coordinates: $scope.values };  

fixed it.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -