ng-select inside modal

See original GitHub issue

NullInjectorError: No provider for InjectionToken ng-select-selection-model! when ng-select is in component opened in modal (eg. ngx-modal)

Component:

export class RegistrationTypeEditComponent implements OnInit, OnDestroy {

  @ViewChild('registrationTypeForm', {static: true}) public form: NgForm;

  public model: any = {};

  constructor(
    public bsModalRef: BsModalRef) {
  }

  ngOnInit(): void {
  }
}

HTML:

<div app-page [width]="'fw-800'">
    <form (ngSubmit)="onSubmit()" #registrationTypeForm="ngForm">
        <div class="row">
            <div class="col-24 form-group">
                <label for="type">{{'lbl.Type' | translate}}</label>
                <ng-select 
                    id="type" 
                    name="type" 
                    [items]="(enums$ | async)?.ERegistrationTypes"                   
                    [hideSelected]="true"
                    bindLabel="label"
                    bindValue="name"
                    [(ngModel)]="model.type"
                    required
                    >
                </ng-select> 
            </div>
        </div>
        <button type="button" class="btn btn-light"  (click)="onCancel()">{{'lbl.Cancel' | translate}}</button>
        <button type="submit" class="btn btn-success float-right" [disabled]="!registrationTypeForm.form.valid">{{'lbl.Submit' | translate}}</button>
    </form>
  </div>

Calling function:

add(): boolean {
    const modalOptions = {
      myInterval: 0,
      noWrapSlides: false,
      initialState: {
        model: {},
      }
    };

    this.bsModalRef = this.bsModalService.show(RegistrationTypeEditComponent, modalOptions);

    return false;
  }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
gustavomickcommented, Jan 29, 2021

@varnastadeus hi, i noticed you closed the issue, but still, seems the only way to fix this is to include NgSelectModuel in AppModule, is this correct? if that so seems not a right solution, appreciate if you give us some feedback about this. thanks!

0reactions
blended-ideascommented, Nov 5, 2020

Got it working, Including NgSelectModule in AppModule solves the issue as NgSelectModule is now not lazy loaded.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ng-select inside dialog add extra hidden height - Stack Overflow
I have a ng-select element inside a component that sits inside a mat-expansion-panel , and the contents at the bottom would get cut...
Read more >
Ng-select inside dialog add extra hidden height (dropdown)
It works fine in bootstrap 4 modal window, but I will have a look that is wrong here. For now quick fix would...
Read more >
Select component inside modal - Material Design for Bootstrap
I want to use the new select component inside a modal. The dropdown is not working like accepted. Generally it's there and I...
Read more >
@ng-select/ng-select - npm
Angular ng-select - All in One UI Select, Multiselect and Autocomplete. ... Start using @ng-select/ng-select in your project by running `npm ...
Read more >
Angular Material2 Issue (forked) - StackBlitz
Issue template for @angular/material.
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