简体   繁体   中英

Angularjs: I want to edit data submitted to my backend nodejs > Mongodb. What is the best design that I should follow?

My application architecture is simple Front end using ionic-angularjs with backend nodejs interfacing with mongodb. My application will require ability to submit data related to reimbursement (say few details such as expenseType, amount, pupose and say date). I am able to design a form which then submits it via a controller using http:post method.

Now comes the stage where I want to provide an ability to edit the form in case I think few details are incorrect. What I have done so far is from my history page, where using cards I am able to display all records submitted till date< I am providing an edit option. The edit captures the claimID from the card scope and then gets the data from backend using http GET method. The data now is available with the controller. I then store them in scope variable and access them from the html form.

Doing this I felt I am making too many calls to the server side for a simple modification request. Wanted to find out if there are other methods and better ones.

Use an instance of $resource as a wrapper around the backend for the cards.

Use input directive of forms in order to perform as much validation as possible client-side, and minimize HTTP connection to the backend.

The GET method is probably required when the form is first opened in the client (if the record for that claimID hasn't already been cached) however subsequent communication about that claimID can all be PUT requests eg PUT /api/claims/123' with a body that contains a JSON of the updated data. If the update is accepted, the backend will return code PUT /api/claims/123' with a body that contains a JSON of the updated data. If the update is accepted, the backend will return code 200 or 204`, and no return body data is necessary. Otherwise, the backend can return only an optimized message indicating which fields failed, eg angularjs validation server side or the like.

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