我是Angular(7+)的新手,在引导选择下拉列表中选择新值时,似乎无法触发selectionChange
事件。
是否缺少某些内容或需要的语法?
我也尝试了(change)和(ngModelChange),但还是没有。 而且控制台中没有错误...
这是我的HTML和组件方法
import {BsDatepickerConfig} from 'ngx-bootstrap';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {
@Output() cancelRegister = new EventEmitter();
user: User;
registerForm: FormGroup;
bsConfig: Partial < BsDatepickerConfig > ;
emailErrorMessage: string;
userErrorMessage: string;
currentYear: number = new Date().getFullYear();
startYear = this.currentYear - 120;
years: number[] = [];
months: string[] = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
countryList = new Countries().countryCode;
inputCity: string;
constructor(private authService: AuthService, private router: Router,
private alertify: AlertifyService, private fb: FormBuilder) {
for (let i = this.currentYear; i > this.startYear; i--) {
this.years.push(i);
}
}
ngOnInit() {
this.bsConfig = {
containerClass: 'theme-red'
};
this.createRegisterForm();
}
onCountryChange(countryObj) {
let test = 0;
}
onCityChange(cityObj) {
let i = 0;
}
...
}
<div class="form-group">
<select (selectionChange)="onCountryChange($event)" id="country" class="form-control">
<option *ngFor="let country of countryList" [value]="country.code" [selected]="country.name == 'United States'">
{{country.name}}
</option>
</select>
</div>
答案 0 :(得分:1)
您可以改用(change)="onCountryChange($event)"
答案 1 :(得分:0)
尝试(ngModelChange)=“ onCountryChange($ event)”