Disable button when input is empty in Angular 2

后端 未结 3 1264
谎友^
谎友^ 2021-01-04 02:37

I want to check whether the input is empty.

  • If not empty, enable the submit button.
  • If empty, disable the submit button.

I tried

3条回答
  •  别那么骄傲
    2021-01-04 03:13

    To bind functions to events, you don't have to prefix them with on. Just place the event.

    For example, if you want to handle the keydown (plunker demo):

    
    

    But in your specific case, since you already are using ngModel you are better off using (ngModelChange):

    
    

    Because it will pick up the changes when the user pastes (via CTRL+V ormouse right click menu -> Paste) the password instead of typing it.

    See plunker demo for using (ngModelChange) here.

提交回复
热议问题