Skip to content

<md-autocomplete> needs change or select event on options #5096

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

Closed
dihar opened this issue Jun 12, 2017 · 5 comments
Closed

<md-autocomplete> needs change or select event on options #5096

dihar opened this issue Jun 12, 2017 · 5 comments

Comments

@dihar
Copy link

dihar commented Jun 12, 2017

Hi!

I need a output event in <option> of <md-autocomplete> when we choose it.

I have a use case:

<md-input-container>
  <input mdInput name="someSideInput" [(ngModel)]="someAnotherProperty">
</md-input-container>

<!--
options: {name: string; sideValue: string}[];
-->

<md-input-container>
  <input mdInput [(ngModel)]="autocompleteProperty" [mdAutocomplete]="autoComp" 
    name="autocompleteInput">
</md-input-container>
<md-autocomplete #autoComp="mdAutocomplete">
  <md-option *ngFor="let opt of options" 
    [value]="opt.name" 
    (click)="someAnotherProperty = opt.sideValue">
    {{ opt.name }}
  </md-option>
</md-autocomplete>

On choose autocomplete's option I need do some side effect with some local template variable (like opt in template). This template is working great. But on key interaction it doesn't work. (keyup) doesn't work. It's need to add output event on option (choose),(select) or (pick) .

The final result I want:

<md-autocomplete #autoComp="mdAutocomplete">
  <md-option *ngFor="let opt of options" 
    [value]="opt.name" 
    (select)="someAnotherProperty = opt.sideValue">
    {{ opt.name }}
  </md-option>
</md-autocomplete>

It must work for click and key interaction.
Thanks!

@julianobrasil
Copy link
Contributor

julianobrasil commented Jun 12, 2017

This feature would be very wellcome with the "force selection" being tracked in here #3334.

In fact, the efect you wish can be done as soon as you garantee the values of the input is one of the options - if the user left the component without selecting one option the input would be cleared.

But it's a lot of code to do a simple thing. It could be present in the component out-of-the-box.

@dihar
Copy link
Author

dihar commented Jun 12, 2017

@julianobrasil , thanks for reference, "force selection" will do component more flexible. About your decision for my case: manipulation with input doesn't work, because it isn't see local variable in option.

@dihar
Copy link
Author

dihar commented Jun 12, 2017

I worked this case out with (onSelectionChange) in mdOption just now. Close the issue or this issue can be useful in other use cases?

@julianobrasil
Copy link
Contributor

Better close.

@dihar dihar closed this as completed Jun 12, 2017
@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 5, 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

2 participants