1

This is just a basic input element I have in my form which I need to set its default initial value.

<input type="number" name="interest_rate" [(ngModel)]="interest_rate">

In my code, I added

this.form.controls['interest_rate'].patchValue(this.assumptions.interest_rate*100);

But I'm getting

Error: Error in :0:0 caused by: Cannot read property 'patchValue' of undefined

1 Answer 1

6

To set default value, just set interest_rate property of a respective component.

@Component({
  ...
  template: `<input type="number" name="interest_rate" [(ngModel)]="interest_rate">`
})

class M {
   interest_rate = 3;
}
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.