mirror of
https://github.com/angular/angular.git
synced 2026-11-22 22:55:25 -05:00
docs: fix the input setter coercion example in the template type checking guide
The "Input setter coercion" section opened with a signal input that uses
`transform: booleanAttribute`, then said that `<submit-button disabled>`
is a type error under strict templates. With that transform the attribute
form compiles, so the example never showed the problem. The rest of the
section is about an `@Input()` setter typed `boolean`.
Use a plain `boolean` getter and setter in the first example so it
matches the text that follows, update the intro sentence to say the value
is altered in the setter, and remove a duplicated "Consider the following
directive:" line.
(cherry picked from commit 567ae3ed66)
This commit is contained in:
@@ -201,22 +201,29 @@ See [Improving template type checking for custom directives](/guide/directives/s
|
||||
|
||||
## Input setter coercion
|
||||
|
||||
Occasionally it is desirable for the `input()` property of a directive or component to alter the value bound to it, typically using a `transform` function for the input.
|
||||
Occasionally it is desirable for an input of a directive or component to alter the value bound to it, typically in the input's setter.
|
||||
As an example, consider this custom button component:
|
||||
|
||||
Consider the following directive:
|
||||
|
||||
```angular-ts
|
||||
@Component({
|
||||
selector: 'submit-button',
|
||||
template: `
|
||||
<div class="wrapper">
|
||||
<button [disabled]="disabled()">Submit</button>
|
||||
<button [disabled]="disabled">Submit</button>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
class SubmitButton {
|
||||
disabled = input.required({transform: booleanAttribute});
|
||||
private _disabled = false;
|
||||
|
||||
@Input()
|
||||
get disabled(): boolean {
|
||||
return this._disabled;
|
||||
}
|
||||
|
||||
set disabled(value: boolean) {
|
||||
this._disabled = value;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user