我在DOM中有2个选择元素。应根据我对第一个选择元素的选择来填充第二个选项。我在这里创建了它的简化版本:https://plnkr.co/edit/tJMjCFp3hQ4PnrGWn3qG?p=preview
@Component({
selector: 'my-app',
template: `
<div>
<select (change)="setResults($event)">
<option value='numbers'>Numbers</option>
<option value='colors'>Colors</option>
</select>
<select>
<option *ngFor = "let op of results" value={{op}}>{{op}}</option>
</select>
</div>
`,
})
export class App {
name:string;
constructor() {
}
public value: string;
public result: any[];
public colors = ['red', 'green', 'blue'];
public numbers = [1, 2, 3, 4, 5];
public setResults(e){
let name = e.target.options[e.target.selectedIndex].value;
console.log(name);
if(name === 'numbers'){
this.result = this.numbers;
console.log(this.result);
}
else
this.result = this.colors;
}
}
现在不行。关于什么是错的任何建议?