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

mat-select option not showing selected value #15099

Closed
muhammedMoussa opened this issue Feb 6, 2019 · 3 comments
Closed

mat-select option not showing selected value #15099

muhammedMoussa opened this issue Feb 6, 2019 · 3 comments

Comments

@muhammedMoussa
Copy link

values display when open select, but when select one no action in option instead of displaying name of selected value.
data coming from api, when it was static was working fine? if this related.
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/material": "^7.2.2"

 <mat-form-field floatLabel="auto">
  <mat-select  formControlName="AccountTypeId">
    <mat-option *ngFor="let acc of account_types" [value]="acc.id">
      {{ acc.AccountTypeNameArabic }}
    </mat-option>
  </mat-select>
</mat-form-field>
@crisbeto
Copy link
Member

crisbeto commented Feb 6, 2019

Sorry, but this isn't a lot to go on. Closing for now, but it can be reopened if there's more info or a Stackblitz showing the issue.

@crisbeto crisbeto closed this as completed Feb 6, 2019
@praveen3484
Copy link

praveen3484 commented May 31, 2019

I am also facing this issue in Angular 7.
I am using dynamic forms with formfactory in angular 7.
When I try to pass these values to the dropdown component then the material dropdown doesn't displays the selected value. The value is indeed there as I've checked it after debugging and on search, the value is passed correctly.
However, the value is not showing as pre-selected in the dropdown.
If I try to manually select any other value then it is displaying normally.

Here is the code from my dropdown component where I've used the material dropdown:
<mat-form-field> <mat-label >{{ model.label}}</mat-label> <mat-select [(value)] = "model.value" [formControlName]="model.key" [placeholder]="model.placeholder" [disabled]="model.disabled" (onChange)="onChange.emit($event)" (onInput)="onInput.emit($event)" (onFocus)="onFocus.emit($event)" (onBlur)="onBlur.emit($event)" [(ngModel)]="model.value" [value] = "1"> <mat-option *ngFor="let option of model.options" [value]="option.value">{{option.label}} </mat-option> </mat-select> </mat-form-field>
Here is the part of snippet from my actual parent ts file where I've used dynamic forms and used formfactory:
this.practiceDropdown= new Dropdown({ key: "practiceId", label: "Practice", });

I set value on this dropdown by following code:
setInputs() {; this.formDropdown.get("practiceId").setValue(this.practiceId); }

Please note that the dropdown works fine if I use Primeng dropdown in the dropdown component instead of the angular material dropdown.:
<p-dropdown [options]="options" [placeholder]="model.placeholder" [disabled]="model.disabled" [autoWidth]="false" (onChange)="onChange.emit($event)" (onInput)="onInput.emit($event)" (onFocus)="onFocus.emit($event)" (onBlur)="onBlur.emit($event)" [formControlName]="model.key" ></p-dropdown>

Any leads would be appreciated.
Cheers!

@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 10, 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