Module 10 - HTML Forms Flashcards

1
Q

Reactive Forms Import

A

import { FormGroup, FormControl, Validators } from ‘@angular/forms’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Reactive Forms Configure

A

this.sheridanForm = new FormGroup({
‘idnumber’: new FormControl(null, Validators.required),
‘login’: new FormControl(null),
‘campus’: new FormControl(‘Davis’)
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Reactive Forms Use

A
<input matInput formControlName="idnumber">`
<input matInput formControlName="login">

```

<input></input>
~~~

<form [formGroup]="sheridanForm" (ngSubmit)="onSubmit()">

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Template Driven Forms Import

A

import { FormsModule } from ‘@angular/forms’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Template Driven Forms Configure

A

<input matInput id=”first” ngModel name=”first” required #first=”ngModel”>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Template Driven Forms Use

A

<form #f=”ngForm” (ngSubmit)=onSubmit(f)”>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the two approaches to working with forms in Angular, and when would you use each?

A
  1. Template-driven forms: Used for simpler forms, where the structure is inferred from the HTML template.
  2. Reactive forms: Used for more complex forms, where the form structure is defined in the TypeScript code.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you handle form submission in a template-driven form using Angular?

A

Form submission is handled using the ngSubmit directive and binding it to a function in the component.

Example:
<form #f=”ngForm” (ngSubmit)=”onSubmit(f)”>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the role of FormGroup in reactive forms, and how is it used?

A

FormGroup is used to group form controls in a reactive form, allowing for the management of the form’s overall state. It is defined in the component’s TypeScript file.

Example:
this.sheridanForm = new FormGroup({
‘idnumber’: new FormControl(null, Validators.required),
‘login’: new FormControl(null),
‘campus’: new FormControl(‘Davis’)
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly