Angular 角度6:路由器参数不与服务一起工作

Angular 角度6:路由器参数不与服务一起工作,angular,Angular,我是angular方面的新手,我正在尝试导航来自API的数据。路由工作正常,它转到其各自的组件,但无法获取地址栏中的数据。并且在控制台中没有显示任何错误。 app-routing.module.ts 我从那里获取数据的服务 hamedani-followers.service.ts 这是我的父组件。其中包含“a”标记(单击事件) section-ten.component.html 我试图从中获取ID的子组件文件 github-profile.component.ts(子组件) 这一行是错误的

我是angular方面的新手,我正在尝试导航来自API的数据。路由工作正常,它转到其各自的组件,但无法获取地址栏中的数据。并且在控制台中没有显示任何错误。

app-routing.module.ts 我从那里获取数据的服务

hamedani-followers.service.ts 这是我的父组件。其中包含“a”标记(单击事件)

section-ten.component.html 我试图从中获取ID的子组件文件

github-profile.component.ts(子组件) 这一行是错误的:

<h5><a [routerLink]="['/section-ten', 'hamedaniFollower.id']">{{hamedaniFollower.url}}</a></h5>
{{hamedaniFollower.url}
它必须是:

<h5><a [routerLink]="['/section-ten', hamedaniFollower.id]">{{hamedaniFollower.url}}</a></h5>
{{hamedaniFollower.url}

或者你只是说
hamedaniFollower.id
是一个普通字符串。

你应该传递
hamedaniFollower.id
而不是
第十节.component.html
文件中的字符串
'hamedaniFollower.id'
。在您定义h5的地方

删除“hamedaniFollower.id”周围的引号谢谢您的回答谢谢您的回答
<div class="cont">
  <h3>Routing</h3>
  <ul class="list-group">
    <li class="list-group-item" *ngFor="let hamedaniFollower of hamedaniFollowers | slice:0:5; let i=index">
      <div class="img_cont">
        <img [src]="hamedaniFollower.avatar_url" />
      </div>
      <div class="text_cont">
        <h4>{{hamedaniFollower.login}}</h4>
        <h5><a [routerLink]="['/section-ten', 'hamedaniFollower.id']">{{hamedaniFollower.url}}</a></h5>
      </div>      
    </li>
  </ul>
</div>
import { Component, OnInit } from '@angular/core';
import { HamedaniFollowersService } from './../../services/hamedani-followers.service';

@Component({
  selector: 'section-ten',
  templateUrl: './section-ten.component.html',
  styleUrls: ['./section-ten.component.scss']
})
export class SectionTenComponent implements OnInit {
  hamedaniFollowers : any;

  constructor(private service: HamedaniFollowersService) { }

  ngOnInit(){
    this.service.getFollowers()
    .subscribe( members => this.hamedaniFollowers = members );    
  }

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

@Component({
  selector: 'app-github-profile',
  templateUrl: './github-profile.component.html',
  styleUrls: ['./github-profile.component.scss']
})
export class GithubProfileComponent implements OnInit {
  constructor(private Routes: ActivatedRoute) { }

  ngOnInit() {
     this.Routes.paramMap.subscribe(params => {
      let id = +params.get('id');
      console.log(params.get('id'));
     })
  }

} 
<h5><a [routerLink]="['/section-ten', 'hamedaniFollower.id']">{{hamedaniFollower.url}}</a></h5>
<h5><a [routerLink]="['/section-ten', hamedaniFollower.id]">{{hamedaniFollower.url}}</a></h5>