Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HostListener is not firing at reset event #16847

Closed
marcosvrs opened this issue May 17, 2017 · 5 comments
Closed

HostListener is not firing at reset event #16847

marcosvrs opened this issue May 17, 2017 · 5 comments

Comments

@marcosvrs
Copy link

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
The @HostListener('reset') in the ngModel is not being fired when the reset event is occured.

Expected behavior
The @HostListener('reset') function must execute when the reset event fired.

Minimal reproduction of the problem with instructions
http://plnkr.co/edit/BYX8RsqUgY4FHvjhyN1X?p=preview
When you submit this, the right result is to reset the input element and clearing the success class, but it is not working. The @HostListener('reset') in the ngModel is not being fired.
The HostListener is at the bs-form-control.directive.ts file and the form/input is at the app.ts file.

What is the motivation / use case for changing the behavior?

Please tell us about your environment:
Windows, VSCode, angular-cli

  • Angular version: 4.1.2

  • Browser: [Firefox 53 | IE 11 ]

  • Language: [TypeScript 2.2 | ES5]

  • Node (for AoT issues): node --version = v7.7.4

@alexzuza
Copy link
Contributor

Why do you expect reset event on input control?

@marcosvrs
Copy link
Author

At the description of the reset function at developer.mozilla.org:

Default Action: Reset the value of all elements of the parent form.
source

I expected the reset event fired on each element of the parent form.

If it is not what occur, how can I listen to the reset event on an input control?

@tytskyi
Copy link

tytskyi commented May 17, 2017

If it is not what occur, how can I listen to the reset event on an input control?

 @HostListener('ngModelChange', ['$event']) onModelChange(value: any) {
    if (!value) {
      console.log("reset?")
      // empty: probably reset, or just erased
      this.handleClasses();
    }
  }

However this does not mean it has been "reset", just empty.

http://plnkr.co/edit/VzHmFj9oFNaxnVxJffPw?p=preview

@marcosvrs
Copy link
Author

Thanks!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants