Trying to send the ngModel back to the component onchange to get it displayed on the console.
Html file: Trying to console.log the ngModel with the help of the log method.
<form action="">
<div class="form-group">
<label for="firstname">First name</label>
<input type="text" id="firstName" name="firstName" #firstName = "ngModel"
(change)="log(ngModel)" ngModel
class="form-control"/>
</div>
<div class="form-group">
<label for="comment">Comment</label>
<textarea id="comment" cols="30" rows="10" class="formcontrol"></textarea>
</div>
<button class="btn btn-primary">Submit</button>
</form>
Component
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-form-contact',
templateUrl: './form-contact.component.html',
styleUrls: ['./form-contact.component.css']
})
export class FormContactComponent {
log(x){
console.log(x);
}
}
getting the following errors:
- No directive found with exportAs 'ngModel'. (name="firstName" #firstName = "ngModel")
- Property 'ngModel' does not exist on type 'FormContactComponent'. ((change)="log(ngModel)"ngModel)
Can someone please direct me in the right direction?
Also, what does ngModel mean here? I understand that [(ngModel)] is a 2-way binding. and [ngModel] would be an attribute and (ngModelChange) would be event together they form 2way binding. What does standalone ngModel represent?