简体   繁体   English

mat-autocomplete 选项值在 IOS 设备中显示不正确

[英]mat-autocomplete the option value does not appear correctly in IOS device

When I select the first option in the dropdown, the option is not reflected in the field.当我 select 下拉菜单中的第一个选项时,该选项没有反映在字段中。 When I select the second option then first option value appears and when selects third the second option value appears. When I select the second option then first option value appears and when selects third the second option value appears. Any suggestions as to what the problem is in my code?关于我的代码中的问题有什么建议吗?

This is happening only on iOS devices.Its working fine on Android and Desktop.这只发生在 iOS 设备上。它在 Android 和桌面上工作正常。

自动完成下拉菜单

 emailDomains = AvailableDomains.emailDomains; export const AvailableDomains = { emailDomains: [ "hotmail.com", "gmail.com", "yahoo.com", "outlook.com" ] }
 <mat-form-field appearance="outline" class="textbox mat-form-field-invalid"> <span class="iconError icon-alert" aria-hidden="false" aria-label="Error"></span> <mat-label>Email</mat-label> <input matInput placeholder="Enter" formControlName="email" type="email" [matAutocomplete]="emailAutoComplete" #email> <mat-autocomplete #emailAutoComplete="matAutocomplete" panelWidth="auto"> <mat-option *ngFor="let emailDomain of (email.value.endsWith('@') && email.value.split('@').length == 2? emailDomains: [])" [value]="email.value + emailDomain">@{{emailDomain}} </mat-option> </mat-autocomplete> </mat-form-field>

I have some auto-complete code that does work on IOS.我有一些在 IOS 上工作的自动完成代码。 I compared the two and the difference I see is that I am using (optionSelected) on the mat-autocomplete tag instead of (onSelectionChange) on the mat-option tag.我比较了两者,我看到的区别是我在 mat-autocomplete 标记上使用 (optionSelected) 而不是在 mat-option 标记上使用 (onSelectionChange)。 Try it and see.试试看。

  <mat-form-field appearance="outline" class="textbox mat-form-field-invalid">
    <span class="iconError icon-alert" aria-hidden="false" aria-label="Error"></span>
    <mat-label>Email</mat-label>
    <input matInput placeholder="Enter" formControlName="email" type="email" [matAutocomplete]="emailAutoComplete" #email>
    <mat-autocomplete #emailAutoComplete="matAutocomplete" panelWidth="auto" (optionSelected)="updateForm($event,emailDomain)">
        <mat-option *ngFor="let emailDomain of (email.value.endsWith('@') && email.value.split('@').length == 2 ? emailDomains : [])"  [value]="email.value + emailDomain">@{{emailDomain}}
        </mat-option>
    </mat-autocomplete>
</mat-form-field>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM