Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - List of events

Tags:

angular

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

like image 386
Omar AMRANI Avatar asked Jan 21 '16 16:01

Omar AMRANI


People also ask

How many events are there in angular?

I am going to share with you a useful list of Angular 13 Event Types for Event Binding. Angular offers plenty of event types to communicate with your app.

What does $event mean in angular?

The $event object often contains information the method needs, such as a user's name or an image URL. The target event determines the shape of the $event object. If the target event is a native DOM element event, then $event is a DOM event object, with properties such as target and target.

What is $event angular 8?

In Angular 8, event binding is used to handle the events raised by the user actions like button click, mouse movement, keystrokes, etc. When the DOM event happens at an element(e.g. click, keydown, keyup), it calls the specified method in the particular component.


1 Answers

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...

like image 75
Langley Avatar answered Sep 29 '22 08:09

Langley