My attempt to create a form in Angular 7 has resulted in an error message: ERROR TypeError: "_co.service.formData is undefined"
Here is the HTML code for the component:
<form (sumbit)="signUp(form)" autocomplete="off" #form="ngForm">
<div class="form-group">
<input name="Name" class="form-control" #Name="ngModel" [(ngModel)]="service.formData.Name" required>
</div>
</form>
This is the TypeScript code snippet:
import { Component, OnInit } from '@angular/core';
import {UserService} from '../../shared/user.service';
import {NgForm} from '@angular/forms';
@Component({
selector: 'app-agent-signup',
templateUrl: './agent-signup.component.html',
styleUrls: ['./agent-signup.component.css']
})
export class AgentSignupComponent implements OnInit {
constructor(private service:UserService) { }
ngOnInit() {
}
signUp(form:NgForm)
{
}
}
Below is the user.service code:
import { Injectable } from '@angular/core';
import {UserData} from './user.model';
import {HttpClient} from '@angular/common/http';
import {environment} from '../../environments/environment';
const API_URL=environment.apiUrl;
@Injectable({
providedIn: 'root'
})
export class UserService {
formData : UserData;
constructor(private http:HttpClient) {}
createUser(formData:UserData)
{
return this.http.post(API_URL+'/user/signup',formData);
}
}
Lastly, here is the user.model class:
export class UserData{
public Email:string;
public Password:string;
public Rera_no:string;
public Name:string;
public Company_name:string;
}
After running into the error "ERROR TypeError: "_co.service.formData is undefined", I'm puzzled. Any guidance on where I might be wrong and how to rectify it would be appreciated.