📜  Angular 10 中的 NgClass 是什么?

📅  最后修改于: 2022-05-13 01:56:25.310000             🧑  作者: Mango

Angular 10 中的 NgClass 是什么?

在本文中,我们将了解 Angular 10 中的NgClass是什么以及如何使用它。

NgClass用于在 HTML 元素上添加或删除 CSS 类

句法:

方法:

  • 创建要使用的 Angular 应用程序
  • 在 app.component.html 中创建一个元素并使用 ngclass 指令设置其类
  • 使用 ng serve 为 Angular 应用程序服务以查看输出

示例 1:

app.component.ts
import { Component, OnInit } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
  
  }


app.component.html
  GeeksforGeeks


app.component.html

  GeeksforGeeks

输出: