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

249
Views
El evento de clic de Angular2 no funciona

Me enfrento a un problema con un evento de clic angular2, no está iniciando un simple console.log o una alerta.

Aquí publico mi plantilla de componentes:

 <div class="col-md-4"> <div *ngFor="let phone of phones"> {{phone.text}} </div> <input class="form-control" type="text" [(ngModel)]="phone"/> <button class="btn btn-primary" (click)="console.log('clicked');" type="button">Call</button> </div>

Cuando hago clic en el botón, no hay nada en la consola.

Traté de ejecutar una función de componente, sin suerte también.

Lo estoy haciendo de la misma manera que aquí: http://learnangular2.com/events/

¿Necesitan más archivos? Simplemente no entiendo por qué esto no funciona.

Muchas gracias, Daniel

Editar:

Ok, ahora lo estoy haciendo así:

Modelo:

 <div class="col-md-4"> <div *ngFor="let phone of phones"> {{phone.text}} </div> <input class="form-control" type="text" [(ngModel)]="phone"/> <button class="btn btn-primary" (click)="callPhone();" type="button">Call</button> </div>

Y mi componente de archivo ts:

 import {Component, OnInit, OnDestroy} from '@angular/core'; import {FormControl} from '@angular/forms'; import {CallService} from '../call.service'; @Component({ moduleId: module.id, selector: 'app-call-formular', templateUrl: './call-formular.component.html', styleUrls: ['./call-formular.component.css'], providers: [CallService] }) export class CallFormularComponent implements OnInit, OnDestroy { phones = []; connection; phone; constructor(private callService: CallService) { } callPhone(): any { console.log('callPhone executed.'); } ngOnInit() { this.connection = this.callService.getPhones().subscribe(phone => { this.phones.push(phone); }); } ngOnDestroy() { this.connection.unsubscribe(); } }

Y todavía no lanza mi evento de clic.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Deberías hacerlo en el archivo ts.

 (click)="myFunc();"

y dentro del archivo .ts

 myFunc():any{ console.log('clicked'); }
about 4 years ago · Santiago Trujillo Report

0

Así que sí, al final la "solución" fue realmente estúpida...

Usé lo que me dijo @Sajeetharan, pero el "problema" era que Chrome mantenía el caché de alguna manera, incluso borrándolo con Ctr + shift + R.

En algún momento eliminé el caché de Chrome y funcionó.

¡Gracias a todos!

Editar:

Así que aquí explico cómo lo hice:

Acabo de agregar algunas configuraciones al host virtual, por lo que no necesito usar el modo de incógnito de Chrome, y lo que agregué es:

 # DISABLE ALL CACHING WHILE DEVELOPING <FilesMatch "\.(html|htm|js|css|json)$"> FileETag None <IfModule mod_headers.c> Header unset ETag Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Note "CACHING IS DISABLED ON LOCALHOST" Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT" </IfModule>

De nuevo, ¡gracias a todos!

about 4 years ago · Santiago Trujillo Report

0

Agregue su lógica en backend/mecanografiado :

 CallClick(): any { console.log('clicked'); }

Y en el lado html :

 <button class="btn btn-primary" (click)="CallClick()" type="button">Call</button>
about 4 years ago · Santiago Trujillo 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!