0
0
Angularframework~10 mins

Form submission handling in Angular - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to bind the form submission to the handler method.

Angular
<form ([1])="onSubmit()">
  <button type="submit">Submit</button>
</form>
Drag options to blanks, or click blank then click option'
AngSubmit
Bsubmit
Cclick
Dchange
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' event on the form tag instead of 'ngSubmit'.
Using 'submit' event which is native but Angular prefers 'ngSubmit'.
2fill in blank
medium

Complete the code to prevent the default form submission behavior.

Angular
onSubmit(event: Event) {
  event.[1]();
  console.log('Form submitted');
}
Drag options to blanks, or click blank then click option'
AstopPropagation
BdetachEvent
CstopImmediatePropagation
DpreventDefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using stopPropagation which only stops event bubbling.
Using stopImmediatePropagation which is not needed here.
3fill in blank
hard

Fix the error in the form control binding to correctly update the model.

Angular
<input type="text" [[1]]="name" (ngModelChange)="name=$event" />
Drag options to blanks, or click blank then click option'
AformControlName
Bvalue
CngModel
DformControl
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' which is one-way binding only.
Using 'formControl' or 'formControlName' without importing ReactiveFormsModule.
4fill in blank
hard

Fill both blanks to create a reactive form with a control named 'email'.

Angular
this.form = new Form[1]({
  email: new Form[2]('')
});
Drag options to blanks, or click blank then click option'
AGroup
BControl
CArray
DBuilder
Attempts:
3 left
💡 Hint
Common Mistakes
Using FormArray instead of FormGroup for a single form.
Confusing FormBuilder with FormControl.
5fill in blank
hard

Fill all three blanks to handle form submission and reset the form.

Angular
onSubmit() {
  if (this.form.[1] === 'VALID') {
    console.log(this.form.[2]);
    this.form.[3]();
  }
}
Drag options to blanks, or click blank then click option'
Astatus
Bvalue
Creset
Dcontrols
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'controls' instead of 'status' to check validity.
Trying to reset form by setting value to empty instead of calling reset().