【发布时间】:2019-09-13 07:23:23
【问题描述】:
这是 componet.ts 文件中的 ngOnInit
ngOnInit() {
this.locationService.getLocation().subscribe( locations => {
this.locations = locations;
});
}
<a [routerLink]="['/locations-list']">
当我使用[routerLink] 导航到上述组件时,它会导航到该组件并加载视图,但它不会触发上述 ngOnInit 方法。但是,如果我刷新页面,它就可以正常工作。
上面的问题有解决办法吗?
我已经使用href 导航到页面,并且使用href 上述方法始终可以正常工作,但速度很慢。这就是我将href 更改为[routerLink] 的原因。
这是包含视图的component.html
<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>
【问题讨论】:
-
试试这些:
<a routerLink="/locations-list">或<a [routerLink]="locations"> -
你重定向到同一个页面吗??
-
从'@angular/core'导入{组件,OnInit};
-
@ram12393 不在同一页面
-
@kashif 已经存在了
标签: angular typescript angular-routerlink