No way to get the selected item value out of dynamically created mat-select
See original GitHub issueWhat is the expected behavior?
Being able to get the selected value out of a dynamically created mat-select control with document.getNativeElement or any other way
What is the current behavior?
NativeElement created by mat-select does not hold the selected value
What are the steps to reproduce?
<mat-form-field>
<mat-select id={{column.columnName}} placeholder="{{column.columnName|translate|capitalize}}">
<mat-option *ngFor="let foreignRow of foreignDataMap[getForeignTableName(column.columnName)]" [value]="foreignRow.uid">
{{foreignRow.value}}
</mat-option>
</mat-select>
</mat-form-field>
var element = document.getElementById( column.columnName ) as HTMLInputElement;
element.value <-- does not exist
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
All latest.
Is there anything else we should know?
No.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Angular get value from dynamically generated mat select
With this code I make a dynamically generated mat select and an input, but I don't know how to get the value from...
Read more >Select | Angular Material
Getting and setting the select value. The <mat-select> supports 2-way binding to the value property without the need for Angular forms.
Read more >Angular Material Select : Getting and Setting value
Angular Material Select is created using mat-select which is a form control for selecting a value from a set of options.
Read more >Angular 12 Material Mat-Select Example - Local and Dynamic ...
In this Angular Material tutorial, we'll discuss how to implement the Select box ... 10) Get Selected Value from MatSelect or Native Select....
Read more >Access Angular Material's MatSelect Options Panel Container
In this article we're going to explore how you can programmatically access the Angular Material Select panel, without doing strange global ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think you need to consider a different approach to the problem.
Option 1 - Change Events Every time a change happens, update a component variable to access later.
Option 2 - Reactive Forms Bind to the generated control name, then access this control when you need the value.
I’ve updated my stackblitz example with both of these options, i’ve kept the native control option there for reference.
https://stackblitz.com/edit/angular-material2-issue-1symtn
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.