stock.component.ts,报错

来源:3-8 resolve守卫

qq_愤世嫉俗的青年_0

2018-01-03

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

@Component({
 selector: 'app-stock',
 templateUrl: './stock.component.html',
 styleUrls: ['./stock.component.css']
})
export class StockComponent implements OnInit {
   private stock:Stock;
   private focus: boolean = false;
   private isPro: boolean;
 constructor(private routeInfo: ActivatedRoute) { }

   ngOnInit() {
      this.routeInfo.data.subscribe((data:{stock:Stock}) ==> {
           this.stock= data.stock
       });
      this.isPro=this.routeInfo.snapshot.data[0]["isPro"];

   }


}

isFocus()
{
   return this.focus;
}


}

export class Stock{
   constructor(public id: number, public name: string) {

   }

写回答

1回答

happy3158357

2018-01-07

你是报:

StockComponent.html:5 ERROR TypeError: Cannot read property 'id' of undefined

这个错误吗?

你在app-routing.module.ts中有定义:

resolve: {
    stock: StockResolve
}

吗?

你在stock.component.html中,插值正确吗?

<p>
股票ID是{{stock.id}}
</p>

检查拼写。

最后是在不行,copy代码,不要手写,跑一遍。


另外,提问的时候报啥错可以贴一下吧。


提问的智慧

如何有效地报告bug

0
0

Angular4.0从入门到实战 打造股票管理网站

Angular新特性,教你熟练使用 Angular 和 Typescript 开发组件式单页应用

2683 学习 · 1361 问题

查看课程