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

Trigger displayValue without using FormControl #9

Closed
melroy89 opened this issue Apr 7, 2018 · 5 comments
Closed

Trigger displayValue without using FormControl #9

melroy89 opened this issue Apr 7, 2018 · 5 comments

Comments

@melroy89
Copy link
Contributor

melroy89 commented Apr 7, 2018

I know you can set a new (default) value via the formControl reactive forms.

By creating a new FormControl:

ours = new FormControl(...);

And set the value via:

this.ours.setValue(3);

But since I don't want to provide any input element for the end-user to set a value, but rather my components knows which is the current value to set as default (retrieved from the database), I have the feeling this FormControl is overkill for me.

Is there another way to trigger displayValue(..) without using FormControl?

Thanks in advance.

Kind regards,
Melroy

@melroy89
Copy link
Contributor Author

melroy89 commented Apr 7, 2018

Nevermind, I think this is how Angular just works..

@melroy89 melroy89 closed this as completed Apr 7, 2018
@kylecordes
Copy link
Contributor

Yes, that's correct. This is just the Angular API for setting up a form control value, nothing specific to this search and select widget.

@melroy89
Copy link
Contributor Author

melroy89 commented Apr 9, 2018

Exactly. And since you are using ControlValueAccessor, you can just use the 2 way binding on your component/module by using the [(ngModel)] attribute.

Like so:

<search-select
  placeholder="Debit Ledger account"
  width="100%"
  debounceTime="400"
  [dataSource]="ledgerSearchSource"
  [formControl]="debitControl"
  [(ngModel)]="journal.journal_ledger_debit_id"></search-select>

Which is actually not explained (or I miss a demo). Maybe just once again, add an usage 👍 somewhere -->
https://github.com/OasisDigital/angular-material-search-select

Ps. why do you not use the accessor called SelectControlValueAccessor?

@kylecordes
Copy link
Contributor

@Danger89 As you point out it is possible to use both reactive forms and template forms with ngModel, but we don't recommend that here so we definitely don't show it in any example code. (Actually, we rarely used template forms at all.)

The control being bound to is not a search control, so I don't believe a SelectControlValueAccessor would be correct.

@melroy89
Copy link
Contributor Author

melroy89 commented Apr 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants