3

I'm trying to wrap my mind arround angular components, to understand components better I'm developing a simple todo crud using the component architecture.

The problem is that I think it makes sense to put all operations of the crud in a single controller thus respecting the single responsibility principle but at the same time it is a good practice (I think) to split the views (one for list todos and delete another to create/update todos).

I know that multiple views with a single controller can be achieved using two separate components registering the same controller and some ng/ui-route magic, but using this blows up the encapsulation proposal that the components try to offer.

So, has anyone figured out a good solution to this problem?

4
  • take a look at angular2 todo, it will give you the idea github.com/ColinEberhardt/angular2-todo Commented Jul 25, 2016 at 19:56
  • Can you write a basic code to see what is your issue? crud functions should be put in a service not in a controller. Commented Jul 26, 2016 at 11:55
  • @HadiAmiri thanks for the comment but the scope of the angular2 todo is simple, so all operations were implemented in a singe view (the todo has only one field). Commented Jul 26, 2016 at 16:51
  • @gyc thanks for the comment, I agree, all the crud operations has to be implemented and angular has the $resource which make it easy, the problem I described appears when it makes sense to split the component in multiple views but the controller must be the same to respect the single responsibility principle. Commented Jul 26, 2016 at 16:58

2 Answers 2

1

I think you have to consider always the modularity, so you can use create a service to handle all the crud and API operations and it can be reused by your other controllers and directives. Here is an example of how we did in our project. This is the git repo of on of my partners.

https://github.com/leog/epsilon

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

1 Comment

Thanks for the answer , I read the first part of your series , might be what I need I will read the rest and analyze the project.
1

Here is demo from jhipster repository link

Using angular ui-router in bank-account.state.js described all states with views and controllers.

1 Comment

thanks for the answer, that looks great! the only probleam I see is that the components cannot be export to another project that don't respect the view structure.

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.