AngularRouteParam未解析
创始人
2024-10-29 06:00:40
0

如果Angular Route Param未解析,则可以使用ActivatedRoute服务来访问路由参数。以下是使用ActivatedRoute解析参数的示例:

在路由模块中定义路由:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MyComponent } from './my.component';

const routes: Routes = [
  { path: 'my/:id', component: MyComponent }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class MyRoutingModule {}

在组件中使用ActivatedRoute服务解析参数:

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

@Component({
  selector: 'app-my',
  template: `
    

Routing parameter value: {{ id }}

` }) export class MyComponent implements OnInit { id: number; constructor(private route: ActivatedRoute) {} ngOnInit() { this.route.paramMap.subscribe(params => { this.id = +params.get('id'); }); } }

在上面的示例中,ActivatedRoute服务用于访问路由参数,然后在ngOnInit()方法中将值设置为组件属性。最后,将组件属性绑定到模板中以显示参数值。

相关内容

热门资讯

wpk真吗!竞技联盟辅助插件(... wpk真吗!竞技联盟辅助插件(透视)攻略-其实曝光存在有挂1、竞技联盟辅助插件辅助器安装包、竞技联盟...
hhpoker的辅助是真的吗!... hhpoker的辅助是真的吗!we-poker是什么软件(透视)技巧-都是专业是有挂1、hhpoke...
wejoker辅助机器人!aa... wejoker辅助机器人!aapoker插件下载(透视)挂-真是教你真的是有挂暗藏猫腻,小编详细说明...
pokemmo脚本辅助器下载!... 您好,pokemmo脚本辅助器下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【1367043...
wepoker透视脚本!hhp... wepoker透视脚本!hhpoker软件安装包(透视)工具-真是有挂存在有挂在进入hhpoker软...
wepoker辅助软件视频!德... wepoker辅助软件视频!德普之星辅助器怎么用(透视)攻略-其实解迷真的有挂德普之星辅助器怎么用辅...
hhpoker视频巡查真的假的... hhpoker视频巡查真的假的!wepoker有辅助功能吗(透视)方法-都是必备真的有挂1、下载好h...
拱趴大菠萝辅助神器!wepok... 拱趴大菠萝辅助神器!wepoker透视器免费(透视)方法-一直揭露真的有挂1、让任何用户在无需拱趴大...
HH平台挂!hhpoker德州... HH平台挂!hhpoker德州真的假的(透视)教程-本来必备真的是有挂1、让任何用户在无需hhpok...
哈糖大菠萝免费辅助器!wepo... 哈糖大菠萝免费辅助器!wepoker有人用过吗(透视)工具-果然解密真的是有挂1、上手简单,内置详细...