Skip to content

Commit 25a6b78

Browse files
authored
docs: update coercion coding standards (angular#28491)
1 parent 82ecf0d commit 25a6b78

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

CODING_STANDARDS.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,13 @@ behaviors can be composed. Instead, [TypeScript mixins][ts-mixins] can be used t
258258
common behaviors into a single component.
259259

260260
#### Coercion
261-
Component and directive inputs for boolean and number values must use a setter to coerce values to
262-
the expected type using cdk/coercion.
261+
Component and directive inputs for boolean and number values must use an input transform function
262+
to coerce values to the expected type.
263263
For example:
264264
```ts
265-
@Input() disabled: boolean;
266-
get disabled(): boolean { return this._disabled; }
267-
set disabled(v: BooleanInput) { this._disabled = coerceBooleanProperty(v); }
268-
private _disabled = false;
265+
import {Input, booleanAttribute} from '@angular/core';
266+
267+
@Input({transform: booleanAttribute}) disabled: boolean = false;
269268
```
270269
The above code allows users to set `disabled` similar to how it can be set on native inputs:
271270
```html

0 commit comments

Comments
 (0)