我有一个队列,它本身有一个人数组。在队列中,我想显示人员模板中定义的每个人。
队列.ts
import {Component} from 'angular2/core';
import {Person} from '../person/person';
@Component({
selector: 'queue',
directives: [Person],
template: `<div class="queue">
<person *ngFor="#tP of people"></person>
</div>`
})
export class Queue {
people = [];
constructor(){
this.addPerson(new Person("Bob",20));
this.addPerson(new Person("Jane",30));
this.addPerson(new Person("Dog",40));
this.addPerson(new Person("Cat",50));
};
addPerson(tP:Person):void
{
this.people.push(tP);
}
}
个人.ts
import {Component} from 'angular2/core';
@Component({
selector: 'person',
template: `<div class="person">
<div class="name">{{name}}</div>
<div class="age">{{age}}</div>
</div>`
})
export class Person {
constructor(public name:string = "", public age:number = 5){};
setName(newName:string):void{
this.name = newName;
}
}
我希望什么
<div class="queue">
<div class="person"><div class="name">Bob</div><div class="age">20</div></div>
<div class="person"><div class="name">Jane</div><div class="age">30</div></div>
<div class="person"><div class="name">Dog</div><div class="age">40</div></div>
<div class="person"><div class="name">Cat</div><div class="age">50</div></div>
</div>
我得到了什么
例外:没有字符串的提供者![队列中的人员@1:16] 中的(人员 -> 字符串)
概括
我想使用指令本身定义的模板呈现指令列表。