AngularJS $http.post removing attributes

后端 未结 1 2012
清歌不尽
清歌不尽 2021-01-12 06:28

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

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


        
1条回答
  •  一整个雨季
    2021-01-12 06:57

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

    $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).

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

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

    0 讨论(0)
提交回复
热议问题