角路由参数未定义

时间:2020-02-05 12:58:27

标签: routing parameter-passing undefined angular-routing

在侧边栏中,当我单击调用组件的链接时,未传递参数“ id”,并且在URL上未定义。但是,当我使用同一链接从一个组件导航到另一个组件时,它确实传递了ID。我猜边栏没有得到'id'。 第二个问题是因为没有获取ID,没有在AComponent中预填充表单。

URL为http://localhost:4200/acomp/undefined

{path:'acomp/:id' , component:AComponent }

HTML链接

 [routerLink]=" ['/acomp',data.id]"

ts

      ngOnInit() {
          this.id = this.activatedRoute.snapshot.params["id"];
           this.apiService.getItem(this.id).subscribe(response => {
          console.log(response);
            this.data = response;
           })
          }

0 个答案:

没有答案