question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to get the selected item value out of dynamically created mat-select

See original GitHub issue

What 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:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
agpreynoldscommented, Mar 9, 2019

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

0reactions
angular-automatic-lock-bot[bot]commented, Sep 10, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found