0

I would like to know what's the best way to create, edit and show element. Should i create three pages : showElementView.html, editElementView.html and createElementView.html with three differents controllers showElementController.js, editElementController.js and createElementController.js

or

create one page ElementView.html and one controller ElementController.js with and a variable mode that allow me to detect in which mode i am.

Do you have w3c standard, best web practices or something else that explain this to me.

2 Answers 2

1

In my experience, I think that isn't a good idea having just one view, or one controller, that does all the things...

The goal of AngularJS is to decouple as much as possible, for example, if you have to build a CRUD module, a good IDEA is to have one state for each action, this makes your software maintenable, scalable and testable...

Of course you can merge something, but only where there aren't costs, for example, if you have the UPDATE and the CREATE that have the same interface, you can use only one controller and only one view...

Finally, don't care about having many files because is AngularJS

Sign up to request clarification or add additional context in comments.

2 Comments

This is not specialy about angular js but about web pattern. I think i'm doing the right way writing 3 different controllers. But someone told me i'm wrong. And I would like to find best practice that explain how I have to develop this. ( I'm sorry for my really bad english )
When someone says "you are wrong", it is a good practice asking "why", by the way, you can consider to structure your app imagining a tree where your base module is the root and each CRUD action a leaf, having in the middle one module per branch. example: app => user => registration, ecc.
0

Just create a state for each process of your application using stateProvider. Another way is to use routeProvider and set id's to specific actions ie "User wants to edit a form from your html template you wouldn't want to direct him to an entirely new page, You can just simply set an id for that action which will change depending on the condition of that page in that way you can share content.

1 Comment

I know how to do this, but do you have documentation that explain why use multiple views and files ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.