Skip to content

Commit

Permalink
docs: update coercion coding standards (#28491)
Browse files Browse the repository at this point in the history
(cherry picked from commit 25a6b78)
  • Loading branch information
json-derulo authored and crisbeto committed Jan 30, 2024
1 parent 8675ae2 commit 4c62414
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions CODING_STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,13 @@ behaviors can be composed. Instead, [TypeScript mixins][ts-mixins] can be used t
common behaviors into a single component.

#### Coercion
Component and directive inputs for boolean and number values must use a setter to coerce values to
the expected type using cdk/coercion.
Component and directive inputs for boolean and number values must use an input transform function
to coerce values to the expected type.
For example:
```ts
@Input() disabled: boolean;
get disabled(): boolean { return this._disabled; }
set disabled(v: BooleanInput) { this._disabled = coerceBooleanProperty(v); }
private _disabled = false;
import {Input, booleanAttribute} from '@angular/core';

@Input({transform: booleanAttribute}) disabled: boolean = false;
```
The above code allows users to set `disabled` similar to how it can be set on native inputs:
```html
Expand Down

0 comments on commit 4c62414

Please sign in to comment.