Angular [ngClass] vs [class [英] Angular [ngClass] vs [class

查看:593
本文介绍了Angular [ngClass] vs [class的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下片段之间的Angular有何不同:

What is the difference in Angular between the following snippets:

<div [class.extra-sparkle]="isDelightful">
<div [ngClass]="{'extra-sparkle': isDelightful}">


推荐答案

这是特殊的Angular绑定语法

This is special Angular binding syntax

<div [class.extra-sparkle]="isDelightful">

这是Angular编译器的一部分,您无法在此绑定样式后构建自定义绑定变体。唯一支持的是 [class.xxx] =... [style.xxx] =... [attr.xxx] =...

This is part of the Angular compiler and you can't build a custom binding variant following this binding style. The only supported are [class.xxx]="...", [style.xxx]="...", and [attr.xxx]="..."

ngClass 是一个正常的Angular指令,就像你可以自己构建一样

ngClass is a normal Angular directive like you can build it yourself

<div [ngClass]="{'extra-sparkle': isDelightful}">

ngClass 更强大。它允许您绑定类的字符串,字符串数组或对象中的对象。

ngClass is more powerful. It allows you to bind a string of classes, an array of strings, or an object like in your example.

这篇关于Angular [ngClass] vs [class的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆