AngularJS $ http.post移除属性 [英] AngularJS $http.post removing attributes

查看:115
本文介绍了AngularJS $ http.post移除属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我做了 $ http.post 在AngularJS像一个对象:

When I do a $http.post in AngularJS with a object like:

{  name: '232', id: '3434', $type: "API.Models.Fields.ValuesList, API" }

与签名:

$http.post('api/records', model);

$类型属性被删除的镀铬流量监听每次无论价值。

the $type attribute is removed everytime on the chrome traffic listener no matter the value.

有一些秘密$卸妆;?)

Is there some secret $ remover ;) ?

更新:ANGULAR> = 1.3现在已经不删除$ ATTRS

推荐答案

是,在 $ HTTP 服务发送数据时角条以美元prefixed属性。

Yes, Angular strips dollar-prefixed properties when sending data over $http service.

$ HTTP服务中使用 angular.toJson 串行化的方法对象JSON字符串。此法条
因为角度使用这个符号内部(如实例方法 $保存适用于所有 ngResource 对象)与领先的$字符属性

$http service serialises objects to JSON string using angular.toJson method. This method strips properties with leading $ characters because angular uses this notation internally (e.g. instance method $save is available on all ngResource objects).

快速的解决办法是将它传递给之前手动字符串化数据(透过JSON.stringify), $ HTTP

Quick workaround is to stringify the data manually (using JSON.stringify), before passing it on to $http:

$http.post('/api/path', JSON.stringify(model));

这篇关于AngularJS $ http.post移除属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆