Sample questions
Question 1Easy
Which two main approaches does Angular provide for building forms?
- Static and dynamic forms
- Template-driven and reactive forms
- Imperative and declarative modules
- Client and server forms
Answer: B. Template-driven and reactive forms
Explanation
Template-driven forms rely on directives in the template; reactive forms are built in code with FormControl and FormGroup.
Step-by-step solution
- Angular uses templates to build forms with directives.
- Reactive forms are created using classes like FormControl.
- Template-driven forms use HTML for form logic.
- These two methods are called Template-driven and reactive forms.
- Final answer: B (Template-driven and reactive forms).
Why the other options are wrong
- A. Static and dynamic forms are not Angular's two approaches; the two are template-driven and reactive.
- C. Imperative and declarative modules are not Angular's form approaches; forms use template-driven or reactive styles.
- D. Client and server forms are not an Angular division; the two approaches are template-driven and reactive.
Question 2Easy
What is two-way binding syntax in templates?
- (ngModel)="name" which only listens for events
- [(ngModel)]="name"
- [ngModel]:"name" with a colon
- {{ngModel}}=name as interpolation
Answer: B. [(ngModel)]="name"
Explanation
The banana-in-a-box combines property and event binding.
Step-by-step solution
- [()] combines both.
Why the other options are wrong
- A. Parentheses only listen to events; two-way needs brackets as well.
- C. A colon is not valid binding syntax; use brackets around ngModel.
- D. Curly braces interpolate text; they do not create a two-way binding.
Question 3Easy
Which module provides ngModel in template-driven forms?
- ReactiveFormsModule
- HttpClientModule
- RouterModule
- FormsModule
Answer: D. FormsModule
Explanation
FormsModule enables ngModel and ngForm.
Step-by-step solution
- Template-driven needs FormsModule.
Why the other options are wrong
- A. Reactive forms use ReactiveFormsModule, not ngModel in templates.
- B. HttpClientModule handles HTTP calls, not template-driven form binding.
- C. RouterModule provides routing directives, not ngModel.
Question 4Easy
Which property indicates that a form control has passed all validators?
- touched
- pristine
- dirty
- valid
Answer: D. valid
Explanation
control.valid is true when there are no errors.
Step-by-step solution
- Validity.
Why the other options are wrong
- A. touched means the control was blurred, not that it passed validators.
- B. pristine means the value is unchanged, not the validation status.
- C. dirty means the value changed, not that validation passed.
Question 5Medium
Which validator ensures a reactive form control is not empty?
- Validators.min
- Validators.nullValidator
- Validators.pattern only
- Validators.required
Answer: D. Validators.required
Explanation
Validators.required flags empty values as invalid.
Step-by-step solution
- Validators.required checks if a value is present in the form control.
- It marks the field as invalid if the input is empty or null.
- This validator is specifically used to ensure required fields are not left blank.
- Other validators like min or pattern do not handle emptiness directly.
- The correct answer is Validators.required.
Why the other options are wrong
- A. Validators.min checks that a number is at least a minimum; it does not check for an empty value.
- B. Validators.nullValidator is a no-op that always passes, so it does not enforce a value.
- C. Validators.pattern checks text against a regex and usually passes empty values, so it does not enforce a value.
Tip: Use Validators.required to prevent empty inputs in reactive forms.
Question 6Medium
Which validator makes a control required?
- Validators.must
- Validators.notNull
- Validators.present
- Validators.required
Answer: D. Validators.required
Explanation
Built-in validators live in Validators.
Step-by-step solution
- Name it.
Why the other options are wrong
- A. Validators.must does not exist in Angular's validator set.
- B. notNull is not an Angular validator; required is the one used.
- C. Validators.present is not a real Angular validator.
Question 7Medium
What does form.valid indicate for a FormGroup?
- At least one control has been touched by the user
- All of its controls are valid
- The form has already been submitted once
- The form has no controls registered in it yet
Answer: B. All of its controls are valid
Explanation
A group is valid only when every child control has passed validation.
Step-by-step solution
- FormGroup's
valid property checks all its controls. - Each control must be valid for the form to be valid.
- If any control is invalid,
form.valid becomes false. - So
form.valid means all controls are valid. - Final answer: All of its controls are valid.
Why the other options are wrong
- A. Touched means the user focused and left a field; form.valid does not depend on that.
- C. Submitting the form does not decide validity; form.valid only reflects the status of the controls.
- D. An empty FormGroup is still valid; having no controls does not make form.valid mean something else.
Tip: Remember: FormGroup is only valid if every control inside it is valid.
Question 8Medium
What do the CSS classes ng-touched and ng-dirty indicate?
- touched: the control was blurred; dirty: its value was changed
- touched: the value passed validation; dirty: the value failed validation
- touched: disabled; dirty: pristine
- They are the same
Answer: A. touched: the control was blurred; dirty: its value was changed
Explanation
Angular adds state classes to controls.
Step-by-step solution
- Touched is about focus lost.
- Dirty is about value change.
Why the other options are wrong
- B. Touched and dirty describe user interaction, not validation results.
- C. Touched and dirty do not mean disabled or pristine.
- D. They describe different states, so they are not the same thing.
Question 9Hard
What does updateOn: 'blur' change?
- Validation and value updates occur when the control loses focus rather than on every keystroke
- Disables validation for the control so that no errors are calculated at all, even when the form is submitted
- Updates only when the form is submitted
- Applies a built-in 500 ms debounce
Answer: A. Validation and value updates occur when the control loses focus rather than on every keystroke
Explanation
updateOn takes change, blur or submit.
Step-by-step solution
- Option on control.
Why the other options are wrong
- B. updateOn blur still validates; it only changes when updates happen.
- C. Blur updates the value on focus loss, not only at form submit.
- D. updateOn blur has no built-in debounce; it waits for focus loss.
Question 10Hard
A custom validator for a FormControl should return what when the value is valid?
- true
- an empty string
- undefined error object
- null
Answer: D. null
Explanation
Validators return an error map or null for valid.
Step-by-step solution
- Valid -> null.
Why the other options are wrong
- A. Booleans are not used.
- B. Strings are not the contract.
- C. Error object means invalid.
Practise all 18 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →