I'm trying to get the input from some textboxes, but for some reason in my first textbox i'm getting the input without any problem. But on the second one i'm not getting any value from it even if i type something inside the textbox.
My html elements (the name input tag works):
<div class="form-group">
<label class="control-label">School name</label>
<input placeholder="Name" type="email" class="form-control" name="name" [(ngModel)]="name"
required>
</div>
<div class="form-group">
<label for="exampleFormControlInput1">School Address *</label>
<input placeholder="Address" type="email" class="form-control" name="sh_address" [(ngModel)]="sh_address"
required>
</div>
My code (this is called when the form is submitted):
public name: string = "";
public sh_address: string = "";
validateNewSchoolData() {
console.log(this.sh_address)
}
I tried your code in a new Angular Version 12 project. Your code works. Do you have imported the FormsModule?
imports: [
FormsModule,
...
],
Can you define the angular version you use or create a running code snippet to test?
I checked the two values by a button onClick event and console.log:
buttonClick() {
console.log(this.name, this.sh_address);
}
https://stackblitz.com/edit/angular-ivy-v51ahs
Greetings!