1.1 传值

  1. <ul>
  2. <li *ngFor="let item of list;let key = index">
  3. <a [routerLink]="[ 'newcontent']" [queryParams]="{aid:key}" >{{key}} -- {{item}}</a>
  4. </li>
  5. </ul>

1.2 接收

  1. 1. 引入接受传值模块
  2. import { ActivatedRoute } from '@angular/router'
  3. 2. 实例化
  4. constructor(public route:ActivatedRoute) { }
  5. 3. 接收传值( 无法直接通过“.”直接获取传值,需要通过订阅的方式获取传值即.subscribe()方法)
  6. ngOnInit() {
  7. //console.log(this.route.queryParams);
  8. this.route.queryParams.subscribe(res=>{
  9. console.log(res);
  10. })
  11. }