Samsung Phone Experiencing Strange Angular Problem

As I work on my Angular app, I encountered an odd problem with the menu component specifically on my Samsung S20 phone (it functions properly in desktop Chrome). The issue arises when I focus on an input field in PicksComponent and then click the hamburger button to toggle the menu. The menu briefly appears, then disappears, and the input field loses focus. However, when I click the hamburger button again, it works as expected. It's puzzling because there shouldn't be any direct communication between MenuComponent and PicksComponent.

app-component.html

<main id="container">
<div class='banner'>websitename</div>
<app-menu></app-menu>
<div id="routerOutlet">
<router-outlet></router-outlet>
</div>
</main>

menu-component.ts

import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";
import { ManageLoginService } from "../manage-login.service";

@Component({
  selector: 'app-menu',
  templateUrl: './menu.component.html',
  styleUrls: ['./menu.component.css']
})
export class MenuComponent implements OnInit {

  constructor(private router: Router,private manageLoginService : ManageLoginService) { }

  mobileWidth: number = 500;
  screenWidth: number = window.innerWidth;
  displayMenuItems: boolean = false;
  loggedIn : boolean = false;

  logout() {
    localStorage.clear();
    this.router.navigateByUrl("/login");
  }

  checkMenu() {
    this.screenWidth = window.innerWidth;
    if(this.screenWidth > this.mobileWidth) {
      this.displayMenuItems = true;
    }
    else {
      this.displayMenuItems = false;
    }
  }

  toggleMenu() {
    this.displayMenuItems = !this.displayMenuItems;
  }

  ngOnInit() {
    this.checkMenu();
    this.manageLoginService.isUserLoggedIn.subscribe(loggedInStatus => this.loggedIn = loggedInStatus)
  }

}
</ul>

picks-component.ts

import { Component, OnInit,ViewChild,ElementRef} from '@angular/core';
import { Router } from "@angular/router";
import { DataService } from "../data.service";

@Component({
  selector: 'app-picks',
  templateUrl: './picks.component.html',
  styleUrls: ['./picks.component.css'],
})

export class PicksComponent implements OnInit {
  constructor(private dataService : DataService,private router: Router) { }

  @ViewChild("playerOne",{static:false}) playerOneField: ElementRef;
  @ViewChild("playerTwo",{static:false}) playerTwoField: ElementRef;
  @ViewChild("playerThree",{static:false}) playerThreeField: ElementRef;
  @ViewChild("playerFour",{static:false}) playerFourField: ElementRef;
  @ViewChild("playerFive",{static:false}) playerFiveField: ElementRef;

  title: string = 'Submit Picks';
  suggestions : any = {"playerOne":[],"playerTwo":[],"playerThree":[],"playerFour":[],"playerFive":[]};
  picks : any = {"playerOne":"","playerTwo":"","playerThree":"","playerFour":"","playerFive":""};
  picksForm : any = {"token":"","players":this.picks};
  enableSuggestions: boolean = true;
  formResponse : any;
  formValid : boolean = true;
  formErrors : string;
  keys : any;
  picksSubmitted : boolean = false;

  focus(elementName : any): void {
    this[elementName].nativeElement.focus();
  }

  displayPlayers(player :any) {
    console.log("HMM");
    localStorage.setItem("picks",JSON.stringify(this.picks));
    if(this.picks[player].length >= 3 && this.enableSuggestions) {
      this.dataService.getSuggestions(this.picks[player]).subscribe(suggestions => this.suggestions[player] = suggestions);
    }
    else {
      this.enableSuggestions = true;
      this.suggestions[player] = [];
    }
  }

  submitForm(form :any) {
    if(this.validateForm()) {
      this.picksForm.token = localStorage.getItem("token");
      this.dataService.sendEmail(form).subscribe(formResponse => this.processResponse(formResponse));
    }
    else {
      this.formValid = false;
    }
  }

  processResponse(response :any) {
    this.formResponse = response;
    if(this.formResponse.error) {
      this.formValid = false;
      this.formErrors = this.formResponse.message;
    }
    else {
      localStorage.removeItem("picks");
      this.picksSubmitted = true;
    }
  }

  select(suggestion : any,player :any) {
    this.enableSuggestions = false;
    this.picks[player] = suggestion.forename + " " + suggestion.surname;
    this.suggestions[player] = [];
    localStorage.setItem("picks",JSON.stringify(this.picks));
  }

  resetForm() {
    this.picks.playerOne = "";
    this.picks.playerTwo = "";
    this.picks.playerThree = "";
    this.picks.playerFour = "";
    this.picks.playerFive = "";
  }

  hideSuggestions() {
    this.suggestions.playerOne = [];
    this.suggestions.playerTwo = [];
    this.suggestions.playerThree = [];
    this.suggestions.playerFour = [];
    this.suggestions.playerFive = [];
  }

  validateForm() : boolean {
    // Create array from object
    this.keys = Object.values(this.picks);
    // Iterate over array
    for(const key of this.keys) {
      if(key.length < 2) {
        this.formErrors = "Please do not leave any picks blank.";
        return false;
      }
    }
    return true;
  }

  ngOnInit() {
    if(localStorage.getItem("picks")) {
      this.picks = JSON.parse(localStorage.getItem("picks"));
      this.picksForm = {"token":"","players":this.picks};
    }
    setTimeout (() => { this.hideSuggestions(); }, 1000);
  }
}

Does anyone have any insights into what might be causing this issue? Feel free to ask for more code if needed. I'm unsure if it's related to mobile Chrome or if I made an error, as I'm relatively new to Angular.

Answer №1

Within the menu component, I noticed a window:resize event binding that was being activated whenever the keyboard on mobile appeared or disappeared, causing the window's height to fluctuate. I made an adjustment to the function so that it would only respond to changes in width, resolving the issue.

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

Accepting undefined in rest parameter of typescript

I'm struggling with an exercise involving Function parameters: The maximum function below has the wrong type. To allow undefined in the rest arguments, you need to update the type of the rest parameter. Fortunately, you don't have to change the ...

Using Angular 8.x for routing with customized outlet names

I am attempting to set up routing in my Angular 8.x application, utilizing lazy loading and named outlets. Here is the current configuration: main-layout.html <header> <app-top-menu></app-top-menu> </header> <mat-sidenav-cont ...

Oops! The react-social-media-embed encountered a TypeError because it tried to extend a value that is either undefined, not a

I recently attempted to incorporate the "react-social-media-embed" package into my Next.js project using TypeScript. Here's what I did: npm i react-social-media-embed Here is a snippet from my page.tsx: import { InstagramEmbed } from 'react-soc ...

Error message "Cannot bind to 'name' because it is not a recognized native property" encountered in Ionic icon configuration

Currently, I am developing a mobile app using Ionic 2 and Angular 2. I encountered an issue when trying to use the [name] property in conjunction with Ionic icons and expressions like this: <icon item-right [name]="result.kind ==='song&apo ...

Comprehending a preserved fragment in the role of a task manager

Exploring two different approaches to using fragments as task holders has brought some interesting insights: Questioning the need for UiFragment in the initial example arises as the second example illustrates direct messaging from the task holder fragment ...

Exploring Angular 2 Paper-Input for Effective Form Management

I've been working on implementing Ng2 FormBuilder with paper-inputs and have successfully managed to get the bindings and validation up and running. You can check out my progress here: https://plnkr.co/edit/tr1wYZFyrn4uAzssn5Zs?p=preview <paper-i ...

The specified route type does not comply with the NextJS route requirements, resulting in an authentication error

Recently, I have encountered an issue with NextJS routes while working on an ecommerce project. I am seeking guidance to resolve this issue, specifically related to my route.ts file which interacts with NextAuth for providers like Google. During developmen ...

Step-by-step guide on filtering an array of objects using Vuejs and TypeScript

For this particular project, I am utilizing Vuejs Typescript with a data structure that looks like this: ["order": { "id":1, "created_at":"2019-12-06T10:22:17Z", "status":"open", ...

Best Practices for Angular 4 Modules

I've been tackling a large project in Angular 4.3.6 and I'm exploring the optimal approach to organizing different navigation items into modules. All modules are loaded lazily. Here is an overview of the navigation: Administration Personal s ...

"Encountering a Vue error while attempting to register the Can component globally with CASL +

I have successfully created a vue + typescript application using vue-cli. I followed the instructions from https://stalniy.github.io/casl/v4/en/package/casl-vue and added the following code: // main.ts import Vue from 'vue'; import App from &apo ...

Utilize the up and down arrow keys to scroll through a description list in React

If you want to navigate through the list of Description Details using the tab and shift tab keys, it can be done easily. The default behavior allows for smooth navigation. <dl> <dt style={{ textAlign: "center" }}>Beast of Bodmin< ...

Executing a service request in Angular 2 using a versatile function

I have a function that determines which service to call and a function template for calling the service returned by that function. This function makes HTTP requests using http.get/http.post, which return an Observable and then perform a map operation on th ...

The Perplexing Problem with Angular 15's Routing Module

After upgrading to Angular 15, I encountered an issue with the redirect functionality. The error message points out a double slash "//" in my code, but upon inspection, I couldn't find any such occurrence. * * PagesRoutingModule: const routes: Routes ...

Exploring the depths of complex objects with the inclusion of optional parameters

I've been working on a custom object mapping function, but I've encountered an issue. I'm trying to preserve optional parameters as well. export declare type DeepMap<Values, T> = { [K in keyof Values]: Values[K] extends an ...

Tips for reusing a Jest mock for react-router's useHistory

When testing my code, I set up a mock for the useHistory hook from react-router-dom like this: jest.mock("react-router-dom", () => ({ useHistory: () => ({ length: 13, push: jest.fn(), block: jest.fn(), createHref: jest.fn(), go ...

Angular 2: Embracing the Power of Hierarchical Selection

My goal is to create cascading selects where each option in a dropdown menu can lead to its own set of unique child options. This will result in a hierarchical structure of selectable items. To accomplish this, I have defined a class named fieldSelect tha ...

Unable to display video advertisements from Smaato Ads in my Android application

I have been attempting to integrate Smaato Video Ads into my Android App. Despite following the guidelines provided by Smaato and referencing their example app, I am unable to successfully display the Smaato Video Ads within my application. The snippet of ...

Generating and setting an object property in TypeScript at runtime

In my code, I have defined an interface as follows: export interface OurHistory { ourHistory?: object; step1?:object; step2?:object; } Within the HistoryComponent class, I am doing the following: export class HistoryComponent implements OnInit, On ...

Using an Object as a Key in Maps in Typescript

I had the intention of creating a Map object in Typescript where an object serves as the key and a number is the value. I attempted to define the map object in the following manner: myMap: Map<MyObj,number>; myObj: MyObj; However, when I tried to a ...

Invoke a method in an Angular 2 component using an HTML event

Can an angular component method be invoked using an HTML event? <shape onclick="myMethodInParentComponent()" > I am unable to use (click) as shape is not recognized by Angular. Shape also contains several unknown sub elements making it impractical ...