Is it possible to convert a JavaScript object to JSON
using angular.toJson
only once in my code? Here is an example:
$scope.task.tags = [{"id":22,"tag":"printer","created_at":"2016-03-15" }];
$scope.create = function(task) {
tmp.tags = angular.toJson(task.tags);
TaskService.create(tmp);
});
In the HTML file:
<input type="text" ng-model="task.tags">
<button class="btn btn-success" ng-click="create(task)">save</button>
However, when clicking on the button
multiple times, it displays {{task.tags}}
differently each time:
1st result:
[{"id":22,"tag":"printer","created_at":"2016-03-15"}]
2nd result:
"[{\"id\":22,\"tag\":\"printer\",\"created_at\":\"2016-03-15\"}]"
3rd result:
[{\\\"id\\\":22,\\\"tag\\\":\\\"printer\\\",\\\"created_at\\\":\\\"2016-03-15 09:59:23\\\"}]\""