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代码,不要手写,跑一遍。
另外,提问的时候报啥错可以贴一下吧。
00
相似问题