Angular 10中的NgStyle是什么

Angular 10中的NgStyle是什么

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

NgStyle用于为一个HTML元素添加一些样式。

语法:

<element [ngStyle] = "typescript_property">
HTML

步骤:

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

示例 1:

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

输出:

什么是Angular 10中的NgStyle?

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册