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');
  }
}

相关内容

热门资讯

德州微扑克辅助!德扑软件高端,... 德州微扑克辅助!德扑软件高端,云扑克德州都是是有挂(详细ai人工智能教程)(1)德州微扑克辅助!德扑...
wepoke辅助技巧!wepo... wepoke辅助技巧!wepoke软件透明挂,wepower让系统发好牌,科技教程(有挂工具)科技教...
微扑克ai辅助!wPk的确真的... 微扑克ai辅助!wPk的确真的有挂,WPK果然真的有挂,攻略方法(有挂详情)1、微扑克系统规律教程、...
智星德州菠萝有挂吗!wpk胜利... 智星德州菠萝有挂吗!wpk胜利跟号有关,德扑之星ai代打(详细辅助挂教程)1、每一步都需要思考,不同...
德扑起手牌胜率图!德州之星辅助... 德扑起手牌胜率图!德州之星辅助透视,wepower德州都是有挂(详细数据软件教程)1、每一步都需要思...
wepokeai代打的胜率!w... wepokeai代打的胜率!wepokeai代打,wepoke有挂 网上,必备教程(有挂解说),亲,...
wpk德州透视辅助(Wpk)w... wpk德州透视辅助(Wpk)wpk透视辅助合作(透视)就是真的有挂(曝光教程);1、超多福利:超高返...
WePoKe外 挂!wepok... WePoKe外 挂!wepoke美元局稳,aapoker能玩(详细透视教程);(需添加指定薇7574...
德州微扑克辅助!德州ai机器人... 德州微扑克辅助!德州ai机器人软件开发,德扑之星一贯存在有挂(详细有外 挂教程)1、德州微扑克辅助a...
wepoke有辅助挂!wopo... wepoke有辅助挂!wopoker辅助软件(透视)WEpoke(一直真的有挂)1、点击下载安装,微...