Ng-select: Object(...) is not a function

Created on 12 May 2018  路  4Comments  路  Source: ng-select/ng-select

Hi,

I'm facing the following problem, someone could help me?

MunicipioFormComponent.html:32 ERROR TypeError: Object(...) is not a function
at handleOptionChange (ng-select.js:2555)
at SafeSubscriber.ngOptions.changes.pipe.subscribe.options [as _next] (ng-select.js:2568)
at SafeSubscriber.__tryOrSetError (Subscriber.js:240)
at SafeSubscriber.next (Subscriber.js:181)
at Subscriber._next (Subscriber.js:122)
at Subscriber.next (Subscriber.js:86)
at TakeUntilSubscriber._next (Subscriber.js:122)
at TakeUntilSubscriber.next (Subscriber.js:86)
at MergeMapSubscriber.notifyNext (mergeMap.js:132)
at InnerSubscriber._next (InnerSubscriber.js:16)

And this is my html page:

<div class="form-group required" formGroupName="uf">
    <label class="control-label" for="uf">UF</label>
    <ng-select formControlName="id" [items]="ufList" bindLabel="descricao" bindValue="id" [(ngModel)]="municipio.uf.id">
    </ng-select>
  </div>

MunicipioFormComponent.ts

ufList: Array<UF> = new Array<UF>();

ngOnInit() {

    this.ufService.search().subscribe((data) => {
      this.ufList = data['data'];
    });

this.form = this.formBuilder.group({
      id: ['', []],
      nome: ['', [Validators.required]],
      codigoMunicipal: ['', [
        Validators.required,
        Validators.minLength(7),
        Validators.maxLength(7),
        Validators.pattern('[0-9]+')
      ]],
      uf: this.formBuilder.group({
        id: ['', [Validators.required]]
      }),
      pais: this.formBuilder.group({
        id: ['', [Validators.required]]
      })
    });
}

Thanks!

All 4 comments

@danilocgraciano you don't need to use ngModel with reactive forms, this probably causes the issue.

Hi, thank you for your help. But the real problem was my array "ufList" was not been converted into a NgOption Array.

Right now, i'm facing the same problem described here https://github.com/ng-select/ng-select/issues/548

please create reproducible example

I am also having the same issue as above. I will try to create a reproducible example. It was working under ng-select 1.xxx and I upgraded to 2.0 with the rxjs compatible package

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iantrudell picture iantrudell  路  3Comments

gitlines picture gitlines  路  4Comments

vincentjames501 picture vincentjames501  路  4Comments

VShkotin picture VShkotin  路  3Comments

shawnshaddock picture shawnshaddock  路  3Comments