2

I'm trying to get a value from my form, but I keep getting this error. This is the code. My formControlName is 'name' for the value, and I am trying to put it in a variable of type Address, a class I created. The variable is newAddress, and the form group is addressForm. Here is the function in which I am trying to implement it, and here is my Address class.

onSubmit() {
    this.newAddress.name = this.addressForm.value['name'];
    console.log(this.newAddress.name);
    this.addressForm.reset({
      name: '',
      addressLine1: '',
      city: '',
      state: '',
      zipcode: '',
     });
      this.addressFormDirective.resetForm();
  }
export class Address {
    name: string;
    addressLine1: string;
    city: string;
    state: string;
    zipcode: string;
}

1 Answer 1

1

firstly initialize it in constructor like

this.newAddress=new Address()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.