无法使用routerlink导航

时间:2018-07-17 09:30:16

标签: typescript angular6

我正在尝试导航到客户的详细信息,但是我正在获得

  

错误:“ [对象对象]”

有人可以帮我解决这个问题吗?我是新手,所以对我来说意义重大。预先感谢!

customer-list.html

<p *ngFor="let c of customers">
  <a [routerLink]="['detail']" [queryParams]="{id: c.id}">{{c.name}}</a>
</p>

customer-detail.ts

  customer: Customer;

  constructor(private route: ActivatedRoute, private cs: CustomerService) {
    this.route.queryParamMap.subscribe(params => {
      this.customer = this.cs.getCustomerById(params['id']);
    });
  }

customer.service.ts

get customers() {
  return this._customers;
}

getCustomerById(id: number) {
  for (let i = 0; i > this._customers.length; i++) {
    const customer = this._customers[i];

    if (customer.id == id) {
      return customer;
    }
  }
 return null;
}

0 个答案:

没有答案