【问题标题】:Angular | how to access a variable from one component to another?角度 |如何从一个组件访问变量到另一个组件?
【发布时间】:2023-01-05 22:43:30
【问题描述】:

我的 user.component.ts 中有这个变量

 urlParams = new URLSearchParams(window.location.search)

  urlVal = this.urlParams.get('token') //This variable

..我想在 navbar.component.ts 中使用它

myToken = //HERE I would like to insert that value

我知道这可能是个愚蠢的问题,但我现在正在研究 Angular。谁能帮我?

【问题讨论】:

标签: angular


【解决方案1】:

依赖 Angular 特性,非必要时不要使用原生 JS。


constructor(private route: ActivatedRoute) {

  console.log(this.route.snapshot.params.token);

}

【讨论】:

  • 谢谢,现在我修复了错误。你知道我怎样才能解决我的问题吗?
猜你喜欢
  • 1970-01-01
  • 2017-11-22
  • 1970-01-01
  • 2017-05-28
  • 2016-09-16
  • 1970-01-01
  • 2020-10-25
  • 2020-06-18
  • 2018-10-18
相关资源
最近更新 更多