1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

(Angular 5) Error: Cannot read property 'setValue' of undefined

Discussão em 'Angular' iniciado por Rafael Corzo, Outubro 4, 2024 às 13:22.

  1. Rafael Corzo

    Rafael Corzo Guest

    I'm initializing my form this way, but when I need to edit it, it does not accept the values

    component.ts

    ngOnInit() {
    this.tinvoiceService.initForm();
    }


    tinvoice.service.ts

    form: FormGroup;

    constructor(
    private _fb: FormBuilder,
    private invoiceService: InvoiceService
    ) {}

    initForm(): void {
    this.form = this._fb.group({
    customer: [null, Validators.required],
    totalPrice: 0,
    purchases: this._fb.array([])
    });

    // initialize stream
    const myFormValueChanges$ = this.form.controls['purchases'].valueChanges;
    myFormValueChanges$.subscribe(purchases => this.updatePurchasesAmount(purchases));

    }


    from the HTML I pass the values

    tinvoice.component.html

    <a
    class="btn btn-outline-info text-info"
    (click)="tinvoiceService.populateForm(invoice)">
    Edit
    </a>


    tinvoice-list.component.ts

    populateForm(invoice) {
    this.form.setValue(invoice);
    }


    by console I have this result

    [​IMG]

    View in StackBlitz

    any ideas?

    Continue reading...

Compartilhe esta Página