我想在http.get调用我的休息服务中使用URL中的ID 这是我当前的网址http://localhost:4200/installation/2 我想从网址中提取2并在调用中使用它,这是我当前的代码:
RouterModule :
path: 'installation/:id', component: InstallationDeviceTableComponent
这是我的 InstallationDeviceTableComponent
export class InstallationDeviceTableComponent implements OnInit {
dataSource = new UserDataSource(this.installdevice);
displayedColumns = [ 'name', 'mac', 'ip'];
constructor(private installdevice: InstallationServiceDeviceService, private activatedRoute: ActivatedRoute) { }
public deviceid = ''
ngOnInit() {
console.log(this.activatedRoute)
this.deviceid = this.activatedRoute.snapshot.params.id;
console.log("deviceid: " + this.deviceid)
}
}
export class UserDataSource extends DataSource<any>{
constructor(private installdevice: InstallationServiceDeviceService) {
super();
}
connect(): Observable<InstallationDevice[]> {
return this.installdevice.GetInstallationDevice(); <- use deviceid as parm to call
}
disconnect() { }
}
我在控制台日志中看到“ 2”没有问题。但是我不知道如何使用 deviceid 作为参数,因为“ UserDataSource”是另一个类,没有ngOnInit。
感谢阅读