I'm trying to come up with a custom select control,
<my-select>
<my-option>Option 1</my-option>
<my-option>Option 2</my-option>
...
</my-select>
which works alright with static text. However, if I introduce bindings
<my-select>
<my-option *ngFor="let option of options">{{option}}</my-option>
</my-select>
{{option}} always renders as empty string (if I replace {{option}} with, say test then everything is working again). Here are my components:
@Component({
selector: 'my-select',
template: `
<ul>
<li *ngFor="let option of options">
{{option.text}}
</li>
</ul>
`
})
export class SelectComponent {
options: OptionComponent[] = [];
addOption(option): OptionComponent {
this.options.push(option);
}
}
@Component({
selector: 'my-option',
template: `
<div #wrapper>
<ng-content></ng-content>
</div>
`,
directives: []
})
export class OptionComponent implements AfterContentInit {
@ViewChild('wrapper') wrapper: ElementRef;
text: string;
constructor(private select: SelectComponent) { }
ngAfterContentInit() {
let text = this.wrapper.nativeElement.innerHTML;
this.text = text ? text : 'EMPTY';
this.select.addOption(this);
}
}
How can I get this to work?
EDIT: Almost forgot, here's a plnkr showing the problem.