This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form> | |
| <label> | |
| Name: | |
| <input type="text" name="name" required> | |
| </label> | |
| <button type="submit">Submit</button> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form #myForm="ngForm"> | |
| <label> | |
| Name: | |
| <input type="text" name="name" [(ngModel)]="name" required> | |
| </label> | |
| <button type="submit">Submit</button> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form #myForm="ngForm"> | |
| <div ngModelGroup="user"> | |
| <label> | |
| Name: | |
| <input type="text" name="name" [(ngModel)]="name" required> | |
| </label> | |
| <div *ngIf="myForm.controls['user']?.controls['name'].invalid && myForm.controls['user']?.controls['name'].touched"> | |
| <div *ngIf="myForm.controls['user']?.controls['name'].errors.required">Name is required</div> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component } from '@angular/core'; | |
| @Component({ | |
| selector: 'app-form', | |
| templateUrl: './form.component.html', | |
| }) | |
| export class FormComponent { | |
| name: string; | |
| onSubmit() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form #myForm="ngForm" (ngSubmit)="onSubmit()"> | |
| <div ngModelGroup="user"> | |
| <label> | |
| Name: | |
| <input type="text" name="name" [(ngModel)]="name" required> | |
| </label> | |
| <div *ngIf="myForm.controls['user']?.controls['name'].invalid && myForm.controls['user']?.controls['name'].touched"> | |
| <div *ngIf="myForm.controls['user']?.controls['name'].errors.required">Name is required</div> | |
| </div> | |
| </div> |
OlderNewer