i've built a simple page in angular which gets some data from a webservice, puts it into variables, and displays them in text boxes (and one check box) and now I need to pass the values of those controls into a function when I click a submit button. I have found a few examples on the web but most either don't work or are too complicated for my needs as a beginner.
I have added a form around my controls like this:
<form #policydetails="ngForm" (ngSubmit)="onClickSubmit(policydetails)">
</form>
And I have added ngModel to each of the input controls. In my ts file I have an interface:
interface policyDetails {
surveyChecked: boolean;
title: string;
name: string;
address1: string;
address2: string;
address3: string;
address4: string;
address5: string;
postcode: string;
telephone: string;
telephone_work: string;
telephone_mobile: string;
email: string;
policy_no: string;
}
And my onClickSubmit function looks like this:
onClickSubmit(policydetails: policyDetails) {
alert(policydetails.title);
}
This seems like it should work, but when I serve the site I get this:
Compiled with problems:X
ERROR
src/app/app.component.html:4:59 - error TS2345: Argument of type 'NgForm' is not assignable to parameter of type 'policyDetails'.
Type 'NgForm' is missing the following properties from type 'policyDetails': surveyChecked, title, address1, address2, and 9 more.
4 <form #policydetails="ngForm" (ngSubmit)="onClickSubmit(policydetails)">
Can anyone tell me what i'm doing wrong? Please try to keep your answer clear and simple as i'm very new to Angular. Thanks!