首页 > 解决方案 > 如何保存从用户那里获得的路由参数的值并将其保存以供其他组件使用?

问题描述

我有一个用户列表,我可以单击其中一个并检索特定的 id(codSoggetto),然后使用路由参数路由到具有该 id 的另一个组件。我想用于其他组件的那个 id 我该怎么做?如何保存或用于其他组件?


    export class ListaUtentiComponent implements OnInit {
  userList: Array<List>;
  public itemcodSoggetto;

  constructor(private _userService: UserService,
              private route: ActivatedRoute,
              private router: Router) {}

  ngOnInit() {
    this.getCafUserList();
   
    let codSoggetto = this.route.snapshot.paramMap.get('codSoggetto');
    this.itemcodSoggetto = codSoggetto;


    
  }

  getCafUserList(): void {
    this._userService
    .getCafUserList()
    .subscribe(res => this.userList = res);
  }

  onSelect(item){
    this.router.navigate(['/homeb', item.codSoggetto]);
    }

}

标签: angular

解决方案


推荐阅读