The option value in mat-autocomplete is not displaying correctly on IOS devices

When I click on the first option in the dropdown menu, it does not display the selected option in the field. However, when I select the second option, then the value of the first option appears, and when I choose the third option, the value of the second option is displayed. Can anyone provide any suggestions or insights into what might be causing this issue in my code?

This problem seems to only occur on iOS devices as everything works fine on Android and Desktop.

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>

Answer №1

I created an auto-complete feature that functions on IOS, however, upon comparison with another code, I noticed a slight difference. The key variation is the usage of (optionSelected) on the mat-autocomplete tag instead of (onSelectionChange) on the mat-option tag. Feel free to test this out and observe the results.

  <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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combining JSON objects in a Pentaho JavaScript JSON by matching keys to merge with an existing JSON document

My goal is to construct a Json document by breaking it down into smaller pieces, with each piece containing the necessary keys to insert the smaller Json bits into the correct json structure. As I am relatively new to JavaScript and still in the process of ...

Angular 4 seems to be experiencing some issues with the EventEmiitter functionality

Hey everyone, I'm new to working with Angular 4 and I've been trying to implement the event emitter concept without success. Here's the code I have in my demo: app.component.ts import { Component } from '@angular/core'; @Compon ...

Exporting Arrays in Ionic Angular with Typescript is an essential feature

When trying to access an exported component in Typescript, there may be issues with importing the module correctly into another component. An error message is displayed when calling the AddToArray method: Cannot read property 'push' of undefi ...

Arranging unrelated divs in alignment

http://codepen.io/anon/pen/Gxbfu <-- Here is the specific portion of the website that needs alignment. My goal is to have Onyx Design perfectly aligned with the right side of the navbar, or to have the navbar extend up to the end of "Onyx Design". The ...

Is it possible to use JavaScript to append elements with a fade-in effect

I'm looking to add an element with a fade-in animation to another class using JavaScript. Can anyone provide guidance on how to achieve this? Here is what I've tried: success:function(data){ $(".new_posts").append(data); $(".new ...

The AJAX request is failing to reach the server

I'm currently using AJAX to populate a dropdown, but for some reason the call isn't reaching the server. Upon checking Firebug, I see the following error: POST 0 status 404 not found This is the code I'm working with: function selec ...

The error message "ch.match is not a function" appeared in the Javascript code

Here are two functions that I need help with: //Function A var ltrToNato = function(ch) { var x = ch; var nato = ('{"A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India" ...

"Navigate through the page by scrolling with your mouse all the way to 100

Is it possible to trigger an action when a user starts scrolling using the mousewheel? I've searched online but all I found was information on 100% scroll on click. I want the window to automatically be scrolled down to 100% as soon as the user starts ...

Unraveling nested JSON structures with varying formats in Javascript or Jquery: Step-by-step guide

var cart = [ { "Items": "", "category": "", "contents": [ { "Apple iPhone": "222", "French": "Bounjour", "id": 1234, "icon": "/images/bg.jpg", "callback": "use()", "pricetag":"false" } ] }, { "Items": "No 2" ...

Automatically trigger the expansion of all panels within Vuetify using code

I'm attempting to use Vuetify 2.3.5 to programmatically control the opening and closing of expansion panels. <v-expansion-panels accordion> <v-expansion-panel v-for="(item,i) in faqs" :key="i"> <div class ...

Issues with rendering Google Maps on google-maps-react persists, stuck endlessly in loading phase

After following the tutorial for google-maps-react, I attempted to display a Google Map in my app using the same structure as the example. However, the map is not rendering. Link to Tutorial There are no errors showing up in my console. Here is the dire ...

Dragging and dropping in Angular does not move to the intended location within a mat dialog

Attempting to manipulate the order of a lengthy list by dragging and dropping items. In a basic component, moving an item is uncomplicated - able to drag it anywhere within the list. While dragging, can scroll through contents beyond visible range and dro ...

Is there a way to perform a nextAuth sign in using Postman?

I am currently working on implementing user authentication using NextAuth. The authentication works perfectly within my webapp, but now I want to test the sign-in functionality using Postman so that I can share the login endpoint. Below is the configuratio ...

Looking to divide a multiple-page .TIFF document into several PNG or JPG files using the sharp module in node.js?

Is there a way to split a single .tiff file with multiple pages into several .png or .jpg files without using ImageMagick or GraphicsMagick due to limitations in my codebase? I am unable to install CLI tools so I'm exploring alternate solutions. I kn ...

Unable to access nativeElement property as @viewChild is not functioning properly

My goal is to focus on a native element when another element is clicked, similar to the HTML attribute "for" but not applicable in this scenario. Despite my efforts, I'm encountering an error: TypeError: Cannot read property 'nativeElement&ap ...

Update the data in a table using Angular

I am currently displaying an array in a table, but I need to make edits to all the values in one specific column of the table. Here is an excerpt from my code: <tr *ngFor="let line of invoice.lines; let index = index"> <td> {{line. ...

JavaScript does not function properly on dynamically loaded content from AJAX requests and it is not relying on

I am currently using ajax to load all content from 'mysite/math/' into math.php. I want to render the loaded math content using katex. KaTeX GitHub Inside math.php, I include the Katex library from the CDN mentioned in the link above. The HTML ...

What is the process for navigating from one page to another in Ionic 2?

I am currently attempting to navigate between pages using ionic 2. I have been studying from the resources provided at https://ionicframework.com/docs/v2/api/navigation/NavController/ export class ApiDemoPage { constructor(public navCtrl: NavControlle ...

Transform jQuery code to its equivalent in vanilla JavaScript

While I am proficient in using jQuery, my knowledge of pure JavaScript is somewhat limited. Below is the jQuery code that I have been working with: $(document).ready(function() { $.get('http://jsonip.com/', function(r){ var ip_addre ...

Initiating a GET request to retrieve the file generated by the server

I am currently delving into the Mean stack and have encountered a challenge with downloading a file from my server-side application using the Angular front end. Despite successfully generating the file on the back end, clicking the download button on the f ...