Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
¿Por qué la función (cambiar) funciona solo si salgo por primera vez?

He escrito este código para verificar si el total de palabras es al menos 3. Funciona cuando pongo menos de 3 palabras y dejo el cuadro de texto haciendo clic afuera o tabulador. pero solo funciona la primera vez si salgo la segunda vez no da, es decir, no hay error. Así que tengo que ir de nuevo y asegurarme de que las palabras sean menos de tres e irme. ¿Como arreglarlo?

 countTotalWords() { let str= this.model.FullName_AR; if(!str) { return; } let totalWords= str.split(' ') .filter(function(n: string) { return n != '' }) .length; if(totalWords < 3) { this.wordCountAchieved= false; Swal.fire( 'minimum 3 words', 'input minimum 3 words', 'error' ) } else { this.wordCountAchieved= true; } }

html

 <input type="text" #nameArabic (change)="countTotalWords()" class="form-control" id="nameAR" [(ngModel)]="model.FullName_AR" name="nameAR" #name="ngModel" required>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Intente hacer un cambio y vea qué sucede la segunda vez porque el cambio solo se activa cuando detecta un cambio en el contenido.

about 4 years ago · Juan Pablo Isaza Report

0

necesitas usar el evento de desenfoque en lugar del cambio

 <input type="text" #nameArabic (blur)="countTotalWords()">
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!