Loading

Quipoin Menu

Learn • Practice • Grow

angular / Template-Driven Forms
mcq
Direction: Choose the correct option

Q1.

How do you bind an input to a model in template-driven forms?
A. `(ngModel)='property'`
B. `[ngModel]='property'`
C. `ngModel='property'`
D. `[(ngModel)]='property'`
Direction: Choose the correct option

Q2.

What is the purpose of `name` attribute with `ngModel`?
A. To identify the element
B. To set the input name
C. To enable validation
D. To register the control with the parent form
Direction: Choose the correct option

Q3.

How do you access the form control state in template?
A. Using `$event`
B. Using template reference variables and local variables
C. Using `this.form`
D. Using `form.controls`
Direction: Choose the correct option

Q4.

What does `ngForm` directive do automatically?
A. Validates the form
B. Resets the form
C. Tracks the form's value and validity
D. Submits the form
Direction: Choose the correct option

Q5.

How do you disable the submit button when form is invalid?
A. `[enabled]='myForm.valid'`
B. `[disabled]='myForm.invalid'`
C. `disabled='invalid'`
D. `[disable]='myForm'`
Direction: Choose the correct option

Q6.

How do you set a default value in template-driven form?
A. Use `value` attribute
B. Use `defaultValue`
C. Use `initial`
D. Set the component property initial value
Direction: Choose the correct option

Q7.

How do you handle form submission?
A. `(formSubmit)='onSubmit()'`
B. `(ngSubmit)='onSubmit()'` on the form
C. `(onSubmit)='submit()'`
D. `(submit)='onSubmit()'`
Direction: Choose the correct option

Q8.

What is the `ngModelGroup` directive used for?
A. To group ngModel
B. To group models
C. To create model groups
D. To create a sub-group of controls within a form
Direction: Choose the correct option

Q9.

How do you check if a specific field has an error in template?
A. `firstName.hasError('required')`
B. `myForm.controls.firstName?.errors?.required`
C. `myForm.errors.firstName.required`
D. Both A and C
Direction: Choose the correct option

Q10.

Can you use template-driven forms with complex validation?
A. Only with built-in validators
B. Only with reactive forms
C. Yes, with custom directives and validators
D. No, only simple validation