Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda