Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Add support for [attr.name.if]="boolean" syntax #1058

@matanlurey

Description

@matanlurey

Similar to [class.name]="boolean", which adds a class 'name' if boolean is true, and removes class 'name' _if boolean is false (or I think null?).

For example:

<button [attr.if.shiny]="isShiny"></button>

Would output <button shiny></button> if isShiny == true, and remove the 'shiny' attribute if isShiny != true. The reason for this new feature, versus re-using the existing [attr.shiny] syntax, is that it strictly coerces the values to strings, and writes them in the template:

<button [attr.shiny]="isShiny"></button>

... outputs <button shiny="true"></button>.

We talked about trying to check, and if the value is a bool use the new behavior, but that is (a) breaking, and (b) not definitive (it's possible for the value to be Object or bool and require runtime checks). It's probably not worth it.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions