Angular数据在路由中无法传递
创始人
2024-10-29 14:30:46
0

数据在路由中的传递可以通过参数传递实现,具体步骤如下:

  1. 在路由声明中添加参数配置,如下所示:
const routes: Routes = [
  { path: 'detail/:id', component: DetailComponent }
];
  1. 在组件中获取参数并处理,如下所示:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/common';

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

  constructor(
    private route: ActivatedRoute,
    private location: Location
  ) { }

  ngOnInit() {
    this.route.params.subscribe((params: Params) => {
      this.id = +params['id'];
      // 处理数据
    });
  }
}

在上面的示例中,通过 ActivatedRoute 服务获取路由参数,并通过 Params 对象获取当前路由的参数。然后,可以对数据进行处理,或者将其发送到其他组件。

相关内容

热门资讯

透视实锤!aapoker免费透... 透视实锤!aapoker免费透视脚本(透视)aapoker能控制牌吗,AA德州教程(有挂规律);1、...
透视ai!wepoker有人用... 透视ai!wepoker有人用过吗,黑侠破解wepoker(详细一直输的号能继续打)1、该软件可以轻...
透视黑科技!aapoker怎么... 透视黑科技!aapoker怎么控制牌(透视)aapoker如何设置胜率,普及教程(有挂揭秘);1、a...
透视玄学!wepoker脚本,... 透视玄学!wepoker脚本,wepokerplus开挂(详细透视底牌);1、进入到wepokerp...
透视模拟器!aapoker发牌... 透视模拟器!aapoker发牌逻辑(透视)aapoker免费透视脚本,2025新版(有挂规律)1、在...
透视安装!wepoker透视有... 透视安装!wepoker透视有用吗,wepoker轻量版透视(详细正确养号方法)1、让任何用户在无需...
透视好友房!aapoker怎么... 透视好友房!aapoker怎么选牌(透视)aapoker透视插件,2025新版(有挂工具);1、许多...
透视新版!wepoker透视脚... 透视新版!wepoker透视脚本下载,wepoker游戏的安装教程(详细破解游戏盒子)小薇(透视辅助...
透视中牌率!aapoker公共... 透视中牌率!aapoker公共底牌(透视)aapoker辅助怎么用,专业教程(有挂规律)1、下载好a...
透视科技!wepoker有没有... 透视科技!wepoker有没有透视方法,wepoker破解工具(详细作弊辅助)wepoker有没有透...