passing data using router

后端 未结 2 1326
庸人自扰
庸人自扰 2021-01-16 04:04

I have a problem with passing data to other component. Here is the example.

 onEdit(data) {
    this.router.navigate([\"/edit\", { state: data }], {
      re         


        
2条回答
  •  甜味超标
    2021-01-16 04:36

    @batgerel, You has an error in your code. must be

    this.router.navigate(['./edit'], 
       { relativeTo: this.activatedRoute, state: { data } })
    

    And, if your component it's not the main app, in ngOnInit

       this.activatedRoute.paramMap.pipe(
                    take(1), //take(1) is for unsubscribe
                    map(() => window.history.state)
                ).subscribe(res => {
                    console.log(res.data)
                })
    

提交回复
热议问题