onselect值matautocomplete文本框的值如何更新另一个输入框

时间:2019-05-06 03:00:07

标签: angular mat-autocomplete

我已经使用过onSelectionChanged事件来获取mat-autocomplete上所选项目的值

<mat-form-field class="container">

        <input type="text"  (input)="onInputChanged($event.target.value)" placeholder="Search addresses ..."
            matInput 
            [formControl]="searchAddress" 
            [matAutocomplete]="auto"
            >  

        <mat-autocomplete (optionSelected)="onSelectionChanged($event)" #auto="matAutocomplete">
          <ng-container *ngFor='let filteredAddresses of addresses'>
              <mat-option *ngFor="let address of filteredAddresses" [value]="address.Text">
                <small>{{address.Text}}</small>
              </mat-option>
              </ng-container>

        </mat-autocomplete>
    </mat-form-field>

如何使用从mat-autocomplete中选择的值更新输入文本项。如何为以下项更新addressLine1:

 <div class="form-group col-md-3 col-sm-3 col-xs-12">
          <label l10nTranslate
            >label.addressLine1</label
          >
          <input
            class="form-control"
            [(ngModel)]='addressLine11'

          />

        </div>

我尝试过类似的事情:

onSelectionChanged(event: MatAutocompleteSelectedEvent) {
        console.log('event',event.option.value);
        this.addressLine11 = event.option.value;
      }

但是由于errorLine11值一直都不存在而给了错误提示。请提出如何更改代码的提示。

1 个答案:

答案 0 :(得分:0)

可能是错字吗? 您可以在没有标签 .addressLine11

的情况下尝试以下吗
<label l10nTranslate>addressLine11</label>