[英]route is not updated when parameters change
我在我的angular應用程序中使用不同的參數調用相同的組件,但是ngOnInit
僅被調用一次。 我該如何解決? 目的是根據參數顯示不同的數據
const routes: Routes = [{
path: 'overviewscorings',
component: MobileSessionOverviewComponent,
pathMatch: 'full'
];
范本:
<ul class = "dropdown-menu">
<li> <a[routerLink] = "['/overviewscorings']"[queryParams] = "{sessionType : 'CHAR'}"> Characteristics </a> </li>
<li> <a[routerLink] = "['/overviewscorings']"[queryParams] = "{sessionType : 'BOL'}"> Bolters </a> </li>
<li> <a[routerLink] = "['/overviewscorings']"[queryParams] = "{sessionType : 'GAP'}"> Gap </a> </li>
</ul>
零件 :
export class MobileSessionOverviewComponent implements OnInit {
fieldMobileSessions: FieldMobileSession[] = [];
selectedItems:
FieldMobileSession[] = [];
sessionType: string;
constructor(private route: ActivatedRoute) {
this.route
.queryParams
.map(params = params['sessionType'])
.subscribe(stats = this.sessionType = stats);
console.log('type ' + this.sessionType); // let fieldMobileSessions = fieldTrialDb.fieldMobileSessions;
this.find();
}
ngOnInit(): void {
console.log('init');
//this.load().subscribe(s =this.fieldMobileSessions = s);
this.route.params.subscribe((params: Params) = {
this.sessionType
})
}
您可以通過以這種方式訂閱route.queryParams來獲取queryParams,
sessionType: string;
constructor(private route: ActivatedRoute){}
ngOnInit(){
this.route.queryParams.subscribe(params => {
this.sessionType = params['sessionType'];
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.