I have a component that I want to use for different router links and reload it with server data based on the connection parameter. From what I saw at the moment, it is suggested that you get inside the ng zone to cause a re-visualization of the components and their children.
I also pass the object from the http request further to the child components.
This is the onInit code component:
ngOnInit(): void { this.route.params.forEach((params: Params) => { let id = +params['id']; this._userHttpService.getUserData(id) .subscribe(UserData=> this._ngZone.run(() => this.UserData= UserData) ); }); }
And this is a premium
<div *ngIf="UserData"> <div class="container-fluid"> <h3>{{UserData.Id}}</h3> <user-tiles [UserData]="UserData"></user-tiles> </div> </div>
Routes work fine, the correct data is retrieved from the server, and the contents inside <h3> updated after a second, and the custom tile components are not re-displayed. UserData is a built-in user element.
angular typescript angular2-routing angular2-components
Hazerd
source share