角度形式不会在选择地址时验证

时间:2017-05-25 20:37:14

标签: forms angular validation

表单使用google places api来获取地址,但点击地址(或使用键盘选择它)不会触发表单的重新验证?

https://plnkr.co/edit/LgEn9t0X2h6BTHGwyJOW?p=preview

我用

更新值
this.registrationForm.patchValue({ adress: adress.formatted_address});

并尝试使用方法

手动触发验证
this.registrationForm.markAsDirty(true);

this.registrationForm.updateValueAndValidity();

但无法让它发挥作用。

1 个答案:

答案 0 :(得分:3)

place_changed事件在角度区域外被触发时,我建议我们应该调用zone.run()

constructor(private zone: NgZone) {}

...
google.maps.event.addListener(this.autocomplete, 'place_changed', () => {
    const place = this.autocomplete.getPlace();
    this.zone.run(() => this.invokeEvent(place));

<强> Forked Plunker

另见

相关问题