简体   繁体   中英

Angular $resource POSTS $promise and $resolved to server on $save

I am having trouble with $resource on one of my angular projects. All of a sudden it has started to mess up the objects that are sent to the server on $save .

Calls to $save on $resource objects does not strip away $resolved and $promise from the JSON data that is posted to my server.

The resource behaves like normal except this.

So If i were to call $save on an article -> this is what's actually being sent to the server:

{
    "id":999,
    "title":"test 2",
    "text":"",
    "file":null,
    "url":null,
    "pdato":"0000-00-00 00:00:00",
    "author_id":0,
    "status":0,
    "lang":"",
    "parent":0,
    "$promise":{},
    "$resolved":true
}

The two last properties are the problem. I've never had this problem on other projects. Is it true that angular filters the resource object through angular.toJson before it sends it to the server, and this operation is supposed to remove the $promise / $resolved properties?

When I do a console.log(angular.toJson(article)); (article is a fetched resource object) - it also logs the $promise and $resolved properties.

What can cause this behaviour?

Turns out I had a different version of angular-resource than angular. Changed my dependencies versions in bower.json to this:

"angular": "~1.3.0",
"angular-resource": "~1.3.0" // this was ~1.2.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM