Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

479
Visualizações
Angular 2 - List of events

I'm newbie to Angular 2. What are the corresponding events from AngularJS to Angular 2? eg: ng-click to (click)

How about ng-init and all others events? I'm not having intellisense in VS .NET, so it's hard to guess.

Any help please!

Thanks

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

The default handled events should be mapped from the original HTML DOM component's events:

http://www.w3schools.com/jsref/dom_obj_event.asp

by just removing the on prefix.

onclick ---> (click)

onkeypress ---> (keypress)

etc...

You can also create your custom events.

However ngInit is not an HTML event, this is part of the Angular's Component lifecycle, and in Angular 2 they are handled using "hooks", which are basically specific method names inside your component that will be called whenever the component enters the specific cycle. Like:

ngOnInit

ngOnDestroy

etc...

over 4 years ago · Santiago Trujillo Relatório

0

Here is the list of events in Angular Please check in the documentation if required for more info

(focus)="myMethod()"
(blur)="myMethod()" 
(submit)="myMethod()"  
(scroll)="myMethod()"

(cut)="myMethod()"
(copy)="myMethod()"
(paste)="myMethod()"

(keydown)="myMethod()"
(keypress)="myMethod()"
(keyup)="myMethod()"

(mouseenter)="myMethod()"
(mousedown)="myMethod()"
(mouseup)="myMethod()"

(click)="myMethod()"
(dblclick)="myMethod()"

(drag)="myMethod()"
(dragover)="myMethod()"
(drop)="myMethod()"
over 4 years ago · Santiago Trujillo Relatório

0

This is one of the big advantages of Angular2. Not every event needs a customized ng-xxx directive anymore.
With custom elements and all other libraries producing all kinds of custom events, this approach doesn't fly.

In Angular2 the (eventName)="expression" binding syntax allows to subscribe to any known and unknown event.

The $event variable is still available (eventName)="myEventHandler($event)"

See also https://angular.io/docs/ts/latest/guide/template-syntax.html#!#event-binding

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda