Reputation: 266
I am new in the field ,i make a form and on submit i print the object on console but we can not get the input values.
this is my form.ts code
import { Component, OnInit,ElementRef} from '@angular/core';
@Component({
selector: 'app-form',
templateUrl: './form.component.html',
styleUrls: ['./form.component.css']
})
export class FormComponent implements OnInit {
constructor() { }
ngOnInit() {
}
onsubmit(form:ElementRef){
console.log(form);
}
}
and this my html code
<div class="formcontainer">
<form (ngSubmit)="onsubmit(formelement)" #formelement="ngForm">
<input type="text" placeholder="Enter your name" id="username" NgModule name="username"><br>
<!-- <input type="email" placeholder="Enter your email" NgModule name="email"><br>
<input type="tel" placeholder="Enter your mobile numberr" NgModule name="mobile-number"><br> -->
<input type="submit" name="" value="Submit">
</form>
</div>
Upvotes: 0
Views: 1891
Reputation: 1149
In html , change NgModule
to ngModel
.
In TypeScript file, change form:ElementRef
to form:NgForm
which is imported from @angular/forms
Upvotes: 3