HTML5 event handling(onfocus and onfocusout) using angular 2

前端 未结 5 1641
逝去的感伤
逝去的感伤 2020-12-02 13:46

I have a date field and I want to remove the place holder by default.

I am using javascript onfocus and onfocusout events for removing pl

5条回答
  •  醉话见心
    2020-12-02 14:36

    Try to use (focus) and (focusout) instead of onfocus and onfocusout

    like this : -

    
    

    also you can use like this :-

    some people prefer the on- prefix alternative, known as the canonical form:

    
    

    Know more about event binding see here.

    you have to use HostListner for your use case

    Angular will invoke the decorated method when the host element emits the specified event.@HostListener is a decorator for the callback/event handler method

    See my Update working Plunker.

    Working Example Working Stackblitz

    Update

    Some other events can be used in angular -

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

提交回复
热议问题