📜  如何使用<mat-chip-list>和<mat-chip>在角材料中?

📅  最后修改于: 2021-05-13 19:07:18             🧑  作者: Mango

Angular Material是一个由Angular团队开发的UI组件库,用于为台式机和移动Web应用程序构建设计组件。为了安装它,我们需要在项目中安装angular,一旦安装,您可以输入以下命令并下载。 mat-chip-list主要用于标签。

安装语法:

ng add @angular/material

方法:

  • 首先,使用上述命令安装角材。
  • 完成安装后,从app.module.ts文件中的’@ angular / material / chips’导入’MatChipsModule’。
  • 然后,使用标签将该标签中的所有标签或项目分组。
  • 标签内,我们需要为每个项目或标签使用标签。
  • 在Angular材料中,我们还有一个称为堆栈芯片列表的芯片列表类型,其中所有芯片或标签都像堆栈一样垂直显示。
  • 为了以这种形式显示,我们需要使用此类名称“ mat-chip-list-stacked”。
  • 如果要更改主题,则可以使用color属性进行更改。从角度上讲,我们有3个主题,它们是主要主题,重音主题和警告主题。
  • 完成上述步骤后,即可服务或启动项目。

项目结构:如下图所示。

代码实现:

app.module.ts:

Javascript
import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { FormsModule } from '@angular/forms'; 
import { MatChipsModule } from '@angular/material/chips'; 
      
import { AppComponent } from './app.component'; 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  
  
@NgModule({ 
  imports: 
  [ BrowserModule, 
    FormsModule, 
    MatChipsModule,
    BrowserAnimationsModule], 
  declarations: [ AppComponent ], 
  bootstrap: [ AppComponent ] 
}) 
export class AppModule { }


HTML

Default Chip List

                Primary theme chip                          Accent theme chip                           Warn theme chip                 Default theme chip


  

Stacked Chip List

                       Primary theme chip                           Accent theme chip                          Warn theme chip                 Default theme chip


app.component.html:

的HTML

Default Chip List

                Primary theme chip                          Accent theme chip                           Warn theme chip                 Default theme chip


  

Stacked Chip List

                       Primary theme chip                           Accent theme chip                          Warn theme chip                 Default theme chip

输出: