-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dataService calls when inside page controllers vs component/directive controllers. #835
Comments
If your component is a presentational component (like a dumb list), you should not put any logic in it and passing the data directly via attr is the good way. If your component is a container component (a view part reused in different views, for example a card with a list and some buttons or a view itself), you should run API calls in the component init life cycle event. Running API calls should be done through angular services, so in fact you are just resolving the promise in the component controller to set data state (the pure data binding) et ui state (loaders). |
Thanks @MarcLoupias thats what I was thinking. Our components all need to be reused throughout the application, hence the thinking to put the call to the dataService inside the component controller, below is an example of one of our components, ignore any syntactical errors:
now, anytime I need to use this component, I can just use |
I have a question open on stack overflow about this, but it basically boils down to this:
We have various pages containing directives / components.
At the minute, all our dataService calls are done within the pageController, then passing data to each directive via attr's.
My proposal is to shift the dataService calls to within the directives controller, thereby separating the component completely from its parent controllers, and means we can just call a component using a single html tag.
Is there a problem with architecting it in this manner?
This is the question on stack overflow which contains some code examples -> https://stackoverflow.com/questions/44258446/angular-project-architecture-controllers-directives-style-guides
The text was updated successfully, but these errors were encountered: