Angular应用程序抑制queryParams查询参数
创始人
2024-10-30 14:30:20
0

要在Angular应用程序中使用queryParams查询参数,需要在路由上声明对应的参数名称。示例代码如下:

在路由定义中声明查询参数名称:

const routes: Routes = [
  { path: 'products', component: ProductListComponent },
  { path: 'products/:id', component: ProductDetailComponent },
  { path: 'login', component: LoginComponent },
  { path: '', redirectTo: '/products', pathMatch: 'full' }
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { enableTracing: true })
  ],
  exports: [
    RouterModule
  ]
})
export class AppRoutingModule { }

在组件中获取并使用查询参数:

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-product-detail',
  templateUrl: './product-detail.component.html',
  styleUrls: ['./product-detail.component.css']
})
export class ProductDetailComponent implements OnInit {
  productId: number;

  constructor(private route: ActivatedRoute) { }

  ngOnInit() {
    this.productId = +this.route.snapshot.queryParamMap.get('id');
  }
}

相关内容

热门资讯

智星德州菠萝外挂!wepoke... 智星德州菠萝外挂!wepoke软件收费是真的吗,(WePoKer)真是是真的有挂(详细透视2025教...
透视好友房(微扑克辅助挂)we... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款游戏中打牌都...
wpk透视辅助!微扑克机器人代... wpk透视辅助!微扑克机器人代打,(德州app)从前真的有挂(详细透视揭秘教程);实战中需综合运用上...
透视ai代打(微扑克ai辅助)... 透视ai代打(微扑克ai辅助)hm3德州辅助怎么购买(详细辅助揭秘教程)都是是有挂1、许多玩家不知道...
wpk透视辅助!wepoke小... 这是一款非常优秀的wpk透视辅助 ia辅助检测软件,能够让你了解到wpk透视辅助中牌率当中全部隐藏参...
透视游戏(wepoke ai辅... 透视游戏(wepoke ai辅助)pokerrrr开挂(详细辅助力荐教程)最初真的是有挂1、每一步都...
德州之星辅助挂!wepoke ... 德州之星辅助挂!wepoke ai代打,(AAPOker)往昔有挂(详细辅助安装教程);玩家在德州之...
透视安卓版(aapoker挂)... 透视安卓版(aapoker挂)wepower软件靠谱吗(详细辅助德州教程)都是有挂是一款可以让一直输...
aapoker透视辅助!wpk... aapoker透视辅助!wpk的下风机制,(wEPoke)一贯有挂(详细辅助分享教程)1、这是跨平台...
透视软件(aapoker挂)扑... 透视软件(aapoker挂)扑克时间辅助(详细辅助教你攻略)一贯存在有挂;小薇(透视辅助)致您一封信...