Is there a way to have an async callback feed an @Input of a Component in Angular 2? (I'm specifically using RC7 right now.)
My goal is to have a hierarchy of wrapper components that serve as interfaces to the service at that level in the hierarchy. The idea is one could use the parent component's interfaces to provide a model to the child component, and so on. In other words, the parent component would provide a getChild(ID) which would then map to an input on the child component to set its model, all in the template:
<parent-comp #parent>
<child-comp
*ngFor="let id of parent.childIds;"
[model]="parent.getChild(id)">
<!-- And so on, with the child's children, etc. -->
</child-comp>
</parent-comp>
The parent component's method wraps a service method which returns a promise (at this point). So the contents of the parent component's getChild() method is the issue since I need to return the instance later.
One solution I've considered is reworking these methods to pass an instance of the model to populate.
// In the parent component
public getChild(id: string): Child {
let child = new Child();
this.service.getChild(id, child);
return child;
}
// In the parent service
public getChild(id: string, model: Child): Promise<Child> {
this.http.get(some_url).toPromise().then(res => model.update(res));
}
Are there better ways of handling this construct, so that a parent component method can provide a model to the child, and so-on?