Search code examples
angularjsngresource

Angular $resource behaviour


I am designing an Edit page for a listing, where the user can upload/remove images.

I am using $resource.query to get an array of the images. However, when I upload a new picture, the UI doesnt update, unless I refresh the page.

I had the idea that $resource would get the latest data from the server. Is that true? Or is it better to cache the data on a service and using javascript to update em


Solution

  • I had the idea that $resource would get the latest data from the server. Is that true?

    No, it's not true. The two-way data binding is present between the data model and the view, not between the api and the client.

    Possible solutions are:

    a) use a web socket

    b) trigger a new $resource query when the user uploads a new picture

    c) dynamically insert the saved model into the collection your UI is bound to when the request is finished