You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -232,11 +232,47 @@ A: use the /deep/ selector along with :host pseudo-class selector.
232
232
233
233
**What does :host-context() pseudo-class selector target?**
234
234
235
-
A: TODO
235
+
A: The :host-context() selector looks for a CSS class in any ancestor of the component host element, up to the document root.
236
236
237
237
**What does the following css do?**
238
238
`:host-context(.theme-light) h2 {
239
239
background-color: red;
240
240
}`
241
241
242
242
A: Will change this component’s background-color to red if the context of the host has the .theme-light class applied.
243
+
244
+
245
+
## Forms Questions:
246
+
247
+
**When do you use template driven vs model driven forms? Why?**
248
+
249
+
A: Template driven forms make more sense for simpler forms, at least in terms of validation. Model driven or Reactive forms lend themselves to easier testing of the validation logic, so if that’s complex, Reactive forms make more sense. There’s also the issue of asynchronous (template driven forms) vs. synchronous (model driven).
250
+
251
+
**How do you submit a form?**
252
+
253
+
PA: use the ngSubmit event binding like so: `<form (ngSubmit)="onSubmit()" ...>`
254
+
255
+
**What's the difference between NgForm, FormGroup, and FormControl? How do they work together?**
256
+
257
+
A: FormGroup tracks the value and validity state of a group of AbstractControl instances. FormControl does the same for an individual control. NgForm is a directive that Angular automatically attaches to each `<form>` tag. It has its own ‘valid’ property which is true only if every contained control is valid.
258
+
259
+
**What's the advantage of using FormBuilder?**
260
+
261
+
A: Reduces repetition and clutter by handling details of control creation for you.
262
+
263
+
**How do you add form validation to a form built with FormBuilder?**
264
+
265
+
A: pass in Validator objects along with the FormControl objects...
266
+
267
+
**What's the difference between dirty, touched, and pristine on a form element?**
268
+
269
+
A: dirty means it contains user data, touched means the user has at least done something with a particular control (perhaps just literally ‘touched’ it by giving it focus?), and pristine means the control has not been touched at all by the user.
270
+
271
+
**How can you access validation errors in the template to display error messages?**
272
+
273
+
PA: use formErrors
274
+
275
+
**What is async validation and how is it done?**
276
+
277
+
A: verifying some field using some asynchronous call (perhaps a server call)... return a `Promise<ValidationResult>` from your validator. When creating a FormControl object, you can pass an asynchronous validator into the constructor (e.g. `new FormControl(‘value’, syncValidator, asyncValidator)`).
0 commit comments