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
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.
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.
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With