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

105
Visualizações
Angular Form Field Options Dissappear After Exiting the Page

In my app, I have a form field that displays a list of options to choose from to the user. When I first enter the page, everything is fine and I can see the list. But if I go to another page and then go back to the page that has the form field, the options are no longer there. And the service that is supposed to display the options doesn't get called in the network. I don't understand why this happens. Here is my code, what should I do to fix this bug?

HTML:

<mat-form-field appearance="outline" fxFlex="100" fxFlex.gt-xs="30" class="w-100-p">                        
                    <mat-label>Receipt Group Type</mat-label>
                    <mat-select formControlName="ReceiptGroupType" 
                        [required]="form.value['StockType'] != 4">
                        <mat-option *ngFor="let prm of receiptGroupTypeList" [value]="prm.Id">
                            {{prm.Name}}
                        </mat-option>
                    </mat-select>
                </mat-form-field>

TS:

    set Product(prm: IProduct) {
        if (prm != this._product && prm != null) {
            this._product = prm;
        }
        if (this._product && this._product.ProductId > 0) {
            this.filterProductCategories = this.productCategories.filter(
                (x) =>
                    x.ProductGroup.ProductGroupId ==
                    this._product.ProductGroup.ProductGroupId
            );
            this.form = new FormGroup({
                ReceiptGroupType: new FormControl(
                    this._product.Receipt.ReceiptGroupType != null ? this._product.Receipt.ReceiptGroupType.Id:0
                ),
            });
        } else {
            this.form = new FormGroup({
                ReceiptGroupType: new FormControl(0),
            });
        }
    }
    get Product(): IProduct {
        return this._product;
    }
 constructor(
        private _adminService: AdminService,
    ) {
        let productId = this._activeRoute.snapshot.params["id"];

        this._adminService.getReceiptGroupList().then((response:IBasicModel[])=>{
            this.receiptGroupTypeList = response;
        });
    }

TS Service:

receiptGroupTypeList: IBasicModel[];
onReceiptGroupTypeListChanged: BehaviorSubject<any> = new BehaviorSubject(
    []
);
async getReceiptGroupList() {
    if (this.receiptGroupTypeList) {
        return undefined;
    }
    return await new Promise((resolve, reject) => {
        this._http
            .get("Parameter/GetReceiptGroupType")
            .subscribe((response: IBasicModel[]) => {
                this.receiptGroupTypeList = response;
                this.onReceiptGroupTypeListChanged.next(
                    this.receiptGroupTypeList
                );
                resolve(this.receiptGroupTypeList);
            }, reject);
    });
}
about 4 years ago · Juan Pablo Isaza
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