This is the ngOnInit in the componet.ts file
ngOnInit() {
this.locationService.getLocation().subscribe( locations => {
this.locations = locations;
});
}
<a [routerLink]="['/locations-list']">
when I use a [routerLink]
to navigate to the above component it navigates to the component and load the view, but it does not trigger above ngOnInit method. But if I refresh the page it works fine.
Is there any fix for above problem.
Already I used href
to navigate to pages and with href
above method works fine always but its very slow. That's why I changes href
to [routerLink]
.
This is the component.html that contains the view
<div class="table-responsive">
<table class="table">
<thead class=" text-primary">
<th>
Location Name
</th>
</thead>
<tbody *ngIf="locations?.length > 0">
<tr *ngFor="let location of locations">
<td *ngIf="location.verified != false">
{{location.locationName}}
</td>
</tr>
</tbody>
</table>
</div>
</div>