Angular 10中的NgClass是什么

Angular 10中的NgClass是什么

在这篇文章中,我们将看到Angular 10中的NgClass是什么以及如何使用它。

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

语法:

<element [ngClass] = "typescript_property">
HTML

步骤:

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

示例 1:

import { Component, OnInit } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
  
  }
JavaScript
<div [ngClass] ="'gfgclass'">
  GeeksforGeeks
</div>
HTML

输出:

什么是Angular 10中的NgClass?

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册