Proposal: Input as Observable
Sorry, I'm not good at English.
@Input property values are provided by parent component. The changes come asynchronously.
And if Input property was changed in the child component (it has the property as own property) , its change detector never notice it.
Goal
- Parent's input data and child's input property should be synchronized.
- Developers should understand that input properties are changed asynchronously.
@Component({ selector: "child" }) class Child { @Input("input") inputValue: Observable<T>; ngOnInit() { this.inputValue.map((value)=>...); } } @Component({ template: ` <child [input]="valueToChild"></child> ` }) class Parent { valueToChild: T; }
Above code does not work. Currently, to receive input as Observable<T>, I must write it like below.
@Component({ selector: "child" }) class Child { @Input("input") inputValue: Observable<T> } @Component({ template: ` <child [input]="valueToChild"></child> ` }) class Parent { valueToChild: Observable<T> = new Observable<T>((observer)=>{ ... observer.next(val); }); }
Example: http://plnkr.co/edit/BWziQygApOezTENdTVp1?p=preview
This works well, but it's not essential. Parent's input data is a simple data originally.
I think this proposal make us happy.
Thanks.