Я создал плункер, чтобы показать, в чем проблема.Компонент не отображается правильно
https://plnkr.co/edit/a7F616WCoKbSGXzlYGsM?p=preview
У меня есть компонент, я хочу использовать в другом компоненте, я импортировать его и добавить его в директивах: [] из компонента декоратора и не делает ...
компонент - list-list.component, его селектор - gb-line-list, и я пытаюсь использовать его в этом файле app/area-list.component.ts.
На первой странице отображается список областей, при нажатии на одну область, я хочу показать детали этой области со списком строк. Вот что список линии, не оказывающая ...
зонально 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);
}
}
линия-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();
}
}
Вы пропустили plnkr: P –
да, Я понял это haha – JCorriveau
селектор селектора: '[gb-line-list]' - это селектор атрибутов, но вы используете его как селектор элементов. Здесь [вы фиксировали плункер] (https://plnkr.co/edit/EbDwX0De64yUJ9pkAM8C?p=preview), изменили строку 14 из области-detail.component.ts – Abdulrahman