Skip to content

Commit ebfc946

Browse files
JeanMecheAndrewKushnir
authored andcommitted
docs: add note about difference between class bindings and ngClass (#62611)
fixes #40623 PR Close #62611
1 parent ddd9258 commit ebfc946

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎adev/src/content/best-practices/style-guide.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class UserProfile {
217217

218218
### Prefer `class` and `style` over `ngClass` and `ngStyle`
219219

220-
Prefer `class` and `style` bindings over using the `NgClass` and `NgStyle` directives.
220+
Prefer `class` and `style` bindings over using the [`NgClass`](/api/common/NgClass) and [`NgStyle`](/api/common/NgStyle) directives.
221221

222222
```html
223223
<!-- PREFER -->
@@ -237,6 +237,8 @@ developers familiar with basic HTML.
237237
Additionally, the `NgClass` and `NgStyle` directives incur an additional performance cost compared
238238
to the built-in `class` and `style` binding syntax.
239239

240+
For more details, refer to the [bindings guide](/guide/templates/binding#css-class-and-style-property-bindings)
241+
240242
### Name event handlers for what they _do_, not for the triggering event
241243

242244
Prefer naming event handlers for the action they perform rather than for the triggering event:

‎adev/src/content/guide/templates/binding.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ When binding `class` to an array or an object, Angular compares the previous val
176176

177177
If an element has multiple bindings for the same CSS class, Angular resolves collisions by following its style precedence order.
178178

179+
NOTE: Class bindings do not support space-separated class names in a single key. They also don't support mutations on objects as the reference of the binding remains the same. If you need one or the other, use the [ngClass](/api/common/NgClass) directive.
180+
179181
### CSS style properties
180182

181183
You can also bind to CSS style properties directly on an element.

0 commit comments

Comments
 (0)