In the component.ts file, you will find the ngOnInit function as shown below:
ngOnInit() {
this.locationService.getLocation().subscribe( locations => {
this.locations = locations;
});
}
<a [routerLink]="['/locations-list']">
While using a [routerLink]
to navigate to the above component, it loads the view but does not trigger the ngOnInit method. However, refreshing the page resolves the issue. Is there a solution for this problem?
I have previously used href
for navigation which always worked fine with the above method, but it was slow. This led me to switch from href
to [routerLink]
.
The following is the content of the component.html file including 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>