我有一个叫做“week-selector”的组件。该组件的目的是允许用户选择他们希望使用或查看的一周。
我对angular还不熟悉,虽然理解了逻辑,但我在向下拉列表中添加选项时遇到了问题。以下代码显示在页面上,但框中没有任何选项。
import { Component, OnInit, Input, Output } from '@angular/core';
import{EventEmitter} from '@angular/core';
export class DropdownValue {
value:string;
label:string;
constructor(value:string,label:string) {
this.value = value;
this.label = label;
}
}
@Component({
selector: 'app-week-selector',
template:
`
<form class = "ui small form segment">
<div id="WeekSubmission">
<h1> Please enter the week you are in: </h1>
<select>
<option> *ngFor="value of values" (click)="selectItem(value.value)"> {{value.label}}">
{{value}}
</option>
</select>
</div>
</form>
`
})
export class WeekSelectorComponent implements OnInit {
values:DropdownValue[];
@Output()
select:EventEmitter<string>;
constructor() {
this.values = [ new DropdownValue('Team','Liverpool')];
this.select = new EventEmitter();
}
selectItem(value){
this.select.emit(value)
}
ngOnInit() {
}
}