当我做 $http.post
在 AngularJS 中使用一个对象,如:
{ name: '232', id: '3434', $type: "API.Models.Fields.ValuesList, API" }
签名:
$http.post('api/records', model);
$type
无论值如何,每次在 chrome 流量监听器上都会删除属性。是否有一些 secret $ 去除剂 ;) ?
更新:Angular >= 1.3 现在不会删除 $ ATTRS。
最佳答案
是的,当通过 $http
发送数据时,Angular 会去除以美元为前缀的属性服务。
$http 服务使用 angular.toJson
将对象序列化为 JSON 字符串方法。这种方法剥
带有前导 $ 字符的属性,因为 angular 在内部使用此表示法(例如,实例方法 $save
可用于所有 ngResource
对象)。
快速解决方法是在将数据传递给 $http
之前手动对数据进行字符串化(使用 JSON.stringify)。 :
$http.post('/api/path', JSON.stringify(model));
关于AngularJS $http.post 删除属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20340305/