I plan to make such an architecture:
store component- - nested
book component
in store - I have a service call that receives data from the service, and I subscribe to the result. As described in angular2 docs (http).
And I want to use this data in nested components: in forms ( formBuilder ), in material design elements, etc.
What is the best way to do this? I am new to angular2.
Store:
book: IBook; constructor(private bookService: BookService) { } ngOnInit() { this.bookService.getBook('1') .subscribe((book) => { this.book = book; }); }
BookService:
... getBook (id): Observable<IBook> { return this.http.get(this.url + '/' + id) .map(this.extractData) .catch(this.handleError); } private extractData(res: Response) { let body = res.json(); return body || { }; } ...
Book:
@Input() book:IBook; constructor() {} ngOnInit() { });
Because if I use async book everywhere (not formBuilder) - everything is fine, but formBuilder needs to update the values ββafter loading the data into the parent component. How can i do this?
javascript angular typescript
byCoder
source share