Skip to content

Commit da642de

Browse files
committed
docs(angular): document the constraints on the boolean attribute helper
1 parent d3f65a8 commit da642de

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

‎packages/angular/src/common/utils/boolean-attribute.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@
1212
* Strings are coerced the same way Angular's `booleanAttribute` coerces them, so `''` (a bare
1313
* attribute) becomes `true` and `'false'` becomes `false`.
1414
*
15-
* Unlike Angular's `booleanAttribute`, `null` and `undefined` are passed through rather than
16-
* coerced to `false`. Components frequently treat them as a state distinct from `false`, and both
17-
* reach inputs routinely from the `async` pipe before its first emission and from form control
18-
* values:
15+
* Angular's own `booleanAttribute` is not used because it coerces `null` and `undefined` to
16+
* `false`. Components frequently treat those as a state distinct from `false`, such as
17+
* `ion-item`'s `detail` resolving `undefined` to a computed default, and both reach inputs
18+
* routinely from the `async` pipe before its first emission and from form control values.
1919
*
20-
* ```tsx
21-
* // `undefined` means "decide based on the mode", which is not the same as `false`
22-
* const showDetail = detail !== undefined ? detail : mode === 'ios';
23-
*
24-
* // a strict comparison also behaves differently for `null` than it does for `false`
25-
* const showHandle = handle !== false;
26-
* ```
20+
* The parameter type is what Angular derives `ngAcceptInputType_*` from, so it decides which
21+
* template bindings compile. Widening it to `unknown` would let any expression through.
2722
*
2823
* Declared as a function rather than an arrow constant because Angular has to resolve input
2924
* transforms statically when compiling a library in partial compilation mode.

0 commit comments

Comments
 (0)