(更改)选择不调用函数角度5

时间:2018-05-18 22:48:33

标签: angular onchange

我在表单中有一个选择:

<form #selectform="ngForm">
        <select
          id="cityselect"
          class="mt-3 text-white"
          autofocus
          (change)="browse()"
          name="cityselect"
          ngModel>
          <option value="" selected>Select Your City</option>
          <option *ngFor="let city of cities"
                  [value]="city.city">{{city.city}}</option>
        </select>
      </form>

和打字稿文件:

import {Component, OnInit, ViewChild,OnDestroy} from '@angular/core';
import {NgForm} from "@angular/forms";
 @ViewChild('selectform') selectform: NgForm;
  browse(){
    console.log('it worked');
    const city = this.selectform.form.value.cityselect;
    this.router.navigate(['/browse', city]);

  }

当我选择一个我当前有两个值时,不会调用浏览功能。不确定我可能做错了什么。我的控制台中没有可能阻止该事件的错误。

0 个答案:

没有答案