options = [];
addOption(newOption: string) {
this.options.push(newOption);
}
完整示例: component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-component',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
options = ['Option 1', 'Option 2', 'Option 3'];
selectedOption = '';
addOption(newOption: string) {
this.options.push(newOption);
}
}
component.html