angular official component devguide
Refactoring Angular Apps to Component Style : teropa.info
Lifecycle hooks in Angular 1.5 : toddmotto.com
Jun 3, 2016
- $onInit
- Using $onInit
- $onInit + “require”
- Real world $onInit + “require”
- $postLink
- Using $postLink
- Real world $postLink
- What $postLink is not
- $onChanges
- What calls $onChanges?
- Using $onChanges
- Cloning “change” hashes for “immutable” bindings
- One-way dataflow + events
- Is two-way binding through “=” syntax dead?
- Using isFirstChange()
- $onDestroy
- Using $onDestroy
One-way data-binding in Angular 1.5 : toddmotto.com
With a parent / child relation ship between component where the parent pass data to the child, it is the practice of binding uni-directionnal instead of bi-directionnal.
bi-directionnal (two way) is
bindings: { obj: '=' }
uni-directionnal (one way) isbindings: { obj: '<' }
Using one way binding break the link with the parent scope. So the child cannot mutate the parent state.
/!\
If an object reference is bound to the child from the parent, if the child mutate a property it will work like two way binding.Another way to exprime difference between two-way and one-way bindings is :
- One way binding is binding the data from the model to the view.
- Two way binding is binding the data from the model to the view and the view to the model. (Also called MVVM)
one-way data flow
stateful components
bindings
)stateless components
bindings: {}
So TLDR is :
See section component design section in inter-component communication part for this design flaws.
The 3 component categories in Angular
Presentational and Container Components : Dan Abramov (ReactJS team, Redux author)
Responsabilities table
Responsabilities per component | View Comp. | Container Comp. | Dumb Comp. |
---|---|---|---|
Read route parameters | YES | NO | NO |
Uses stores and data services | NO | YES | NO |
Display and styling | NO | NO | YES |
Parent and children communicate via a service : angular.io
src Angular 1.5. Components communication. Best practice : stackoverflow.com
I'm using Angular 1.5.9.
Right now I have two components which need to communicate. If I change something in the first one (for example choose item in the list) => second one needs to be changed (item that was chosen needs to be displayed) and vice versa (changing in the second one => change in the first one) I have read about a lot of approaches, so I can manage this in few ways:
- Communication via shareable Service
- Using two way data binding ("=" option in component bindings). Example: https://jsfiddle.net/peter_drinnan/t4q4nrfp/27/
- Using one way data binding with input/output approach. Example: http://stackoverflow.com/questions/36033940/how-to-pass-data-between-child-components-in-angular-1-5-not-using-scope
- Using "require" (some parent component to share data). Example: http://stackoverflow.com/questions/36645065/component-communication-in-angular-1-5
Maybe I miss something? What is the best practice?
Thank you.
2 big flaws :
AngularJS: Cross Component Communication
Events are no more then GOTO in an asynchronous context. (<- assert by me)
Worse then goto :
GOTO still considered harmful? : stackoverflow.com
Add Angular1 Event Patterns/Best Practices
Front-end Application Libraries and Component Architectures
Parent component trigger function in child component
component communication and triggers
Component Interaction in Angular : kfarst.github.io 20170329