ng-admin

POST to a nested resource using ng-admin


The documentation shows an example on how to fetch entities on a nested resource (http://[baseApiUrl]/posts/123/comments) by using an interceptor on the $http Angular service. I'd like to know how to create entities on nested resources. Is this possible on ng-admin without resorting to custom pages?


Solution

  • I've been struggling with this some time and found a work around. I've also tried your interceptor to fetch child objects of some parent object. It works. But I went back to the embedded_list to make also creation and updating of the parent with the child object in one post/put to the backend. So when fetching /posts/123 I also have the comments in the object. Then, after changing some data I PUT the whole object back. That works. There are some problems however. One of them is that 'reference' field types within the embedded_list don't populate properly. You can work around this by adding the same reference field to the editionView() or creationView() (the level above the embedded_list and set label to '' and cssClasses to 'visibility: hidden'. A very bad solution of course but it does work. I still need to ask this to the developers of ng-admin.

    So I now try to use embedded_list as much as possible to be able to put and post objects with child elements in one call to the backend.

    Does this help?