I am trying to send json data from html using an angular controller to mongodb. However, the data displayed in mongodb is not what was expected. The desired outcome is to see the data entered into the textarea exactly as it appears.
[{"id":"1","name":"service type text","type":"password","value":""}]
This is my html code:
<div ng-app="app" class="ng-scope">
<div ng-controller="sendJsonController" class="ng-scope">
<textarea id="inputFields" rows="4" cols="50" ng-model="input"></textarea><br>
<input ng-click="senddata" type="button" value="submit"><br>
</div>
</div>
--- AngularJS Controller ---
var app = angular.module('app', ['ngRoute']);
app.controller('sendJsonController',
function senddata($http, $scope) {
var string = $scope.input;
console.log($scope.input);
var json=angular.toJson(string);
$http.post('fields/addFields', json).success(function (msg) {
$scope.status = msg;
});
});
The output displayed in the mongodb console is:
[{"_id":"55d9df5fd7ee17b83142829a"}]
Expected Output:
[{"id":"1","name":"service type text","type":"password","value":""}]