我正在渲染一个Angular组件以便基于实体的id
显示数据
<a *ngFor="let detail of details" [routerLink]="['/record-details', detail.id">
Go to page {{detail.name}}
</a>
record-details.component.ts
public id;
public issueDetails;
constructor(
private route: ActivatedRoute,
private recordDetailsService: RecordDetailsService,
) {
route.params.subscribe(params => this.id = params.id);
}
async ngOnInit() {
await this.getDetails(this.id);
}
async getDetails(id) {
try {
this.issueDetails = await this.recordDetailsService.getDetails(id);
} catch (e) {
console.error(e);
}
}
但是每当我单击html链接转到新页面时,它只会更改route参数。我也想基于新的id
加载数据
我在做什么错?
app-routing.module.ts
{
path: 'record-details',
canActivate: [AuthGuard],
loadChildren: () => import('./record-details/record-details.module').then(m => m.RecordDetailsModule)
},
record-details-routing.module.ts
const routes: Routes = [
{
path: ':id',
component: RecordDetailsComponent
}
];