1
我有一个JSON对象user.js的如何通过post方法将数据添加到现有的json对象?
[{
"id": 1,
"username": "vishnu",
"password": "password"
},{
"id": 2,
"username": "vishnu2",
"password": "password"
},{
"id": 2,
"username": "[email protected]",
"password": "password"
}]
和我创建了一个服务从它访问数据,现在我想通过使用后相同的服务来添加数据method.help我。如果U可以
angular.module('starter.service')
.factory('authService', function($http) {
var service = {};
service.GetByUsername = function() {
return $http.get('/js/user.json');
}
return service;
})
服务给予above.edit在相同的代码。
添加
"id": 3,
"username": "[email protected]",
"password": "password"
Ÿ成功的载体作用有2个parametrs? –
https://docs.angularjs.org/api/ng/service/$http。数据, 状态,标题,配置,statusText。如果它有帮助,upvote和标志为解决方案的欢呼声 – CodeNashor