When you choose an emoji, the message is automatically sent without having to press the send button

In order to incorporate emojis into our chat, we have decided to utilize the library available at https://github.com/ahkohd/ngx-emoji-picker. However, we are encountering an issue where selecting an emoji from the picker automatically sends the message without allowing users to continue typing or clicking the send button. Below is the relevant code snippet:

SendMessage() {
    if (this.message) {
      console.log('ts', this.receiverData.username);
      this.msgService
        .SendMessage(this.user._id, this.receiverData._id, this.receiverData.username, this.message)
        .subscribe(data => {
          this.socket.emit('refresh', {});
          this.message = '';
        });
    }
  }

  handleSelection(event) {
    console.log(event.char);
    this.message += event.char;
  }

HTML

 <div class="message-input">
            <div class="wrap">
                <div class="colinput">
                    <input [(ngModel)]="message" [ngModelOptions]="{standalone: true}"
                        (keypress)="IsTyping()" type="text" placeholder="Write your message..." />
                </div>
                <i class='attachment'
                (click)="toggled = !toggled"
                [(emojiPickerIf)]="toggled"
                [emojiPickerDirection]="'top'"
                (emojiPickerSelect)="handleSelection($event)">😄</i>
                <button class="submit"><i class="fa fa-paper-plane" aria-hidden="true"></i></button>
            </div>
        </div>

We are seeking insights on what might be causing this particular issue and how it can be resolved.

Answer â„–1

By implementing (ngSubmit)="SendMessage()" within a form tag, any button click within that form will trigger the SendMessage method. This could potentially be causing the issue you are experiencing. One workaround is to utilize a click event specifically on the send button instead.

Answer â„–2

class custom_component implements OnInit, OnDestroy, AfterContentChecked {
  ngAfterContentChecked(): void {
    const emojiButtons: any = document.getElementsByClassName('emoji-button');
    if (emojiButtons.length > 0) {
      // tslint:disable-next-line: prefer-for-of
      for (let i = 0; i < emojiButtons.length; i++) {
          const type = 'type';
          emojiButtons[i][type] = 'button';
      }
    }
  }
}

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

The labels for my Angular Material form within the dialogue are not visible and the styling appears incorrect until I begin inputting information

https://i.sstatic.net/njp4A.png Upon opening the dialogue, I noticed that only the phone number, email, name, and location fields were properly styled, while the others were not and the labels weren't displaying. Prior to adding appearence="out ...

What is causing this error/bug to show up in Angular?

I encountered an error while working on my Angular project that incorporates both front-end and back-end development with Python Flask. Even though the page updates correctly, a database-related error is being displayed in the console. Below are the snippe ...

How can I use a string variable in Angular 2 to create a dynamic template URL

@Component({ selector: 'bancaComponent', templateUrl: '{{str}}' }) export class BancaComponent implements OnInit { str: String; constructor(private http: Http) { } ngOnInit(): void { this.str = "./file.component.html"; } An ...

Difficulty with Angular's Interpolation and incorporating elements

I've encountered an issue with String Interpolation while following an Angular course. In my server.component.ts file, I've implemented the same code as shown by the teacher in the course: import { Component } from "@angular/core"; @Component ( ...

Creating an id automatically using MYSQL with sequelize and typescript is not possible

I recently started using typescript and I am currently following a tutorial. Most tutorials I have come across use a package to automatically generate an id for the table. My query is: Is there a way to configure sequelize to create the table id with auto- ...

Creating key elements in JavaScript with the push() function

I'm working on a basic shopping cart system using JavaScript (Ionic 2 / Angular). In my PHP code, I have the following: <?php $cart = array( 48131 => array( 'size' => 'STANDARD', 'qty' => ...

Can the type of an object be dynamically assigned in Typescript?

I keep encountering the eslint warning "@typescript-eslint/no-unsafe-assignment". This warning occurs when I am trying to extract specific keys and values from a variable that can be assigned objects of different types, with approximately 10 possible class ...

Struggling with CORS Error in Spring Boot/Angular application?

Error message: https://i.sstatic.net/50emd.png Issue found in Security Configuration with @CrossOrigin http.cors(cors->cors.configurationSource(apiConfigurationSource())) @Bean CorsConfigurationSource apiConfigurationSource() { CorsCo ...

What specific type should be used for validations when incorporating express-validator imperative validations?

Having trouble implementing express-validator's imperative validations in TypeScript because the type for validations cannot be found. // reusable function for multiple routes const validate = validations => { return async (req, res, next) => ...

import types dynamically in TypeScript

One of the files I have is called MyFactory.ts. Here is its content: export type CommandFactory = () => string[] | undefined; export enum FactoryIds {commandFactory : 'commandFactory'} Now, my goal is to dynamically import this file into anot ...

Generating a fresh instance of a class that mirrors an already existing instance, all without relying on eval()

I have an object named uniqueObject of an unspecified class and I am in need of creating a duplicate object from the same class. Here's my current approach: I extract the class name using uniqueObject.constructor.name. Then, I generate a new object o ...

As I work on creating a jest snapshot test, I've encountered an issue with TypeScript error while using Redux within the component

Hi, I'm currently working on snapshot testing in Jest with TypeScript and React.js. The component is fetching state from the Redux store, so I've set up a mock store with all the initial states provided. However, the test is failing and the error ...

Executing a Typescript function in an MVC5 cshtml file, optimized with webpack bundling

Brand new to webpack, and I'm facing obstacles in merging MVC components with webpack AND typescript. Take a look at my code combinations below: webpack.config.js: var wbConfigEntries = { "jqkendoMain": [ paths.appjs + "main.ts" ] }; ...

Tips for Saving JWT Token for Server-Side Rendering in Next.js 14 Without Relying on localStorage

Currently, I am encountering a challenge with storing a JWT token in Next.js 14. My goal is to load a page using SSR, but the use of localStorage is not possible in server-side components. Here's my situation: upon logging in, the backend provides a J ...

Retrieving a text file in Angular 8 using an authentication header

I'm attempting to create a download link that allows users to download a record in .txt format. Initially, I used a simple <a> tag: <a href="http://localhost:8080/service/api/downloadFile?fileType=daily&trsDate=20190918">download< ...

Creating reversed/generate URLs from Routes in Angular2 (using typescript)

Is there a way to automatically create a URL from a route using code? For instance, let's say I have a login component defined in my routes: const appRoutes: Routes = [ ... { path: 'login', component: LoginComponent }, ... ]; N ...

Tips for pulling out specific keys from a typed object using an index signature

TL;DR Query: How do I create a type converter in TypeScript that extracts the defined keys from objects typed with index signatures? I am looking to develop a type "converter" in TypeScript that takes a type A as input and outputs a new type B with keys ...

What is the correct approach for detecting object collisions in Phaser 3?

Hey everyone, I'm facing a problem and could use some assistance. Currently, I am trying to detect when two containers collide in my project. However, the issue is that the collision is being detected before the objects even start moving on screen. It ...

I am experiencing difficulties with TypeORM connecting to my Postgres database

Currently, I am utilizing Express, Postgres, and TypeORM for a small-scale website development project. However, I am encountering challenges when it comes to establishing a connection between TypeORM and my Postgres database. index.ts ( async ()=>{ ...

The type '{}' cannot be assigned to type '() =>'

Do you have a TypeScript question? I am curious about how to 'specify' a single object in useState using the incoming properties of id, heading, and text with an interface or similar method. Take a look at the code snippet below: import React, ...