【发布时间】:2016-03-24 00:12:10
【问题描述】:
我创建了一个 plunker,但我似乎无法使其工作,在查看 chrome 控制台时,出现错误,我无法弄清楚为什么......
异常:类型错误:无法读取未定义的属性“toString”
https://plnkr.co/edit/a7F616WCoKbSGXzlYGsM?p=preview
无论如何,我的问题不是关于 plunker,而是创建我的错误的示例。
我有一个想要在另一个组件中使用的组件,我将它导入并添加到指令中:组件装饰器的 [] 并且它不会呈现...
组件是 line-list.component,它的选择器是 gb-line-list,我正在尝试在这个文件 app/area-list.component.ts 中使用它。
我觉得我根本不清楚,但我无法让我的 plunker 示例正常工作。
area-detail.component.ts
import {Component, Input, OnInit} from 'angular2/core';
import {RouteParams} from 'angular2/router';
import {LineListComponent} from './line-list.component';
import {Area} from './area.interface';
import {LineService} from './lines.service';
@Component({
selector: '[gb-area-detail]',
directives: [LineListComponent],
template: `
<div *ngIf="area">
<h2>{{area.name}} area</h2>
<gb-line-list [areaId]="area.id"></gb-line-list>
</div>
`
})
export class AreaDetailComponent implements OnInit {
private area: Area;
constructor(
private _lineService: LineService,
private _routeParams: RouteParams){}
ngOnInit() {
let id = +this._routeParams.get('id');
this._lineService.getArea(id)
.then(area => this.area = area);
}
}
line-list.component.ts
import {Component, OnInit, Input} from 'angular2/core';
import {LineService} from './lines.service';
import {Line} from './line.interface';
@Component({
selector: '[gb-line-list]',
template: `
<ul>
<li *ngFor="#line of lines">{{line.name}}</li>
</ul>
`
})
export class LineListComponent implements OnInit {
@Input() areaId: number;
private lines: Line[];
constructor (
private _lineService: LineService) {}
getLines() {
this._lineService.getLines(this.areaId)
.then(lines => this.lines = lines);
}
ngOnInit() {
this.getLines();
}
}
编辑: 真正的问题在那里定义 Component not rendering properly
【问题讨论】:
-
哦,当我在我的环境中时,我在 chrome 的控制台中没有收到任何错误...
标签: angular