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

using ng-option and reactive form if set form controller value is object not show the label #767

Closed
kathiraashi opened this issue Aug 23, 2018 · 3 comments

Comments

@kathiraashi
Copy link

html code

<ng-select class="NgSelect" formControlName="Status" [searchable]="true">
   <ng-option *ngFor="let Status of _Statuses" [value]="Status">{{ Status.Value }}</ng-option>
</ng-select>

ts code

this.Form = new FormGroup({
         Status: new FormControl(null, Validators.required),
      });
let SetStatus = {_id: 12345, Value: 'Waiting'};
this.Form.controls['Status'].setValue(SetStatus );

set Status to the Form Controls it's working
but not showing the ng-select

if i am using the another ng-select format

'<ng-select [items]="_Statuses" 
                   bindLabel="Value" 
                   class="NgSelect" 
                   formControlName="Status" 
                   [searchable]="true">
</ng-select>'

its working good

how to solve first format error?

@varnastadeus
Copy link
Member

@kathiraashi create reproducible example using stackblitz

@kathiraashi
Copy link
Author

kathiraashi commented Aug 27, 2018

@varnastadeus
Copy link
Member

varnastadeus commented Aug 27, 2018

Here is modified solution, you need to use compareWith https://stackblitz.com/edit/angular-hyg8xh. #666 has detailed explanation why your model is not selected.

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