Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
How to assign <ng-select [multiple]=isMultiple varibale dynamically?

I need to change a select box behavior dynamically. The below approach is not working, because this variable we cannot set dynamically after calling a service. The component will initialize before the service getting triggered. Any workaround we have for such situations?

    <ng-select
             [multiple]=isMultiple
    
    
    ngOnInit(){
        this.testService.isMultiple().subscribe(
            (isMultiple: boolean): void => {
        this.isMultiple = true;
        }
    }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Trigger manual change detection using ChangeDetectorRef.

The value to the isMultiple is assigned from asynchronous operation, which takes some time for the completion of async operation and retrieval of results. So, the angular fails to auto-detect the change of isMultiple. In such cases, we have to manually trigger the change detection once the asynchronous operation has been completed.

import {ChangeDetectorRef} from "@angular/core";

@Component({...})
export class [className] {
  constructor( private _cdref: ChangeDetectorRef ) {}
    
  ngOnInit(){
    this.testService.isMultiple().subscribe(
      (isMultiple: boolean): void => {
        this.isMultiple = true;
        this._cdref.detectChanges();
    }
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda