1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Why isn't my Angular code showing the correct output?

Discussão em 'Angular' iniciado por Racheli, Novembro 5, 2024 às 17:12.

  1. Racheli

    Racheli Guest

    My task was to take an email address into input and check each character, if the character is in Hebrew - convert it to English The problem with the code is that it fails to convert correctly, I wrote the following text in the input field: "r0556" and it was supposed to display "r0556" instead it displays all kinds of double and long characters as you can see in the picture

    This is the code snippet of the html page

    <h1>נא הכנס כתובת מייל</h1>
    <input (keyup)="getLetter($event)" (mouseover)="onComment()" (mouseleave)="offComment()"
    type="text">
    <div id="comment">{{comment}}</div>
    <button type="button" (click)="clickButton()">{{button}}</button>


    And this is the code snippet of the TypeScript page

    import { Component } from '@angular/core';
    import { FormsModule } from '@angular/forms';

    @Component({
    selector: 'app-email-adress',
    standalone: true,
    imports: [FormsModule],
    templateUrl: './email-adress.component.html',
    styleUrl: './email-adress.component.css'
    })
    export class emailAddressComponent {
    comment = "";
    onComment() {
    this.comment = "חובה למלא כתובת מייל"
    }
    offComment() {
    this.comment = "";
    }

    HebrewLetters = ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ', 'ק', 'ר', 'ש', 'ת'];
    EnglishLetters = ['t', 'c', 'd', 's', 'v', 'u', 'z', 'j', 'y', 'h', 'f', 'k', 'n', 'b', 'x', 'g', 'p', 'm', 'e', 'r', 'a', ','];
    emailAddress = "";

    getLetter(eventLetter: any) {
    let inputLetter = eventLetter.target.value;
    let index = this.HebrewLetters.indexOf(inputLetter);

    if (index !== -1) {
    this.emailAddress += this.EnglishLetters[index];
    } else {
    this.emailAddress += inputLetter;
    }

    if (eventLetter.keyCode === 13) {
    eventLetter.target.value = this.emailAddress;
    alert("This email address: " + this.emailAddress);
    this.emailAddress = "";
    }
    }

    button = "@gmail.com";
    clickButton() {
    this.emailAddress += this.button;
    alert("כתובת המייל שנקלטה היא: " + this.emailAddress)
    }

    }


    enter image description here enter image description here

    Continue reading...

Compartilhe esta Página