Angular MDBootstrap 图标
MDBootstrap是一个基于Material Design和bootstrap的Angular UI库,以其无缝和易于使用的组件来制作好看的网页。
在这篇文章中,我们将了解如何在Angular MDBootstap中使用图标。图标是任何元素的视觉代表,可以是一个链接或一些代表。 Angular Bootstrap的图标列表有1400多个可扩展的矢量图标,称为Font Awesome,涵盖了多个主题和用例。在这里,可扩展的矢量图形意味着每个图标在任何尺寸或任何颜色下都看起来很棒。 因为Font Awesome不需要JavaScript,所以它需要关注兼容性。
属性:
- icon。它用于设置图标类别。
- 大小。它用于设置图标的大小等级。
- classInside:用于为元素内部的组件设置类别。
语法:
<mdb-icon fab icon="angular"></mdb-icon>
步骤:
- 下载 Angular MDBootstrap from: https://mdbootstrap.com/docs/angular/getting-started/installation/
- 提取文件并切换到工作目录。
- 使用以下命令在当前项目中安装npm。
npm install
or
npm install -y
- 在创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
- 使用以下命令启动服务器。
ng serve
项目结构:完成安装后,它将看起来像下面这样。
例子1:这是一个基本例子,说明了如何使用图标。
<div id='gfg'>
<h2>GeeksforGeeks</h2>
<h4>Angular MDBootstrap Icons</h4>
<br />
<mdb-icon fab icon="angular"
class="green-text pr-2" size='4x'>
</mdb-icon>Angular
<br>
<mdb-icon fab icon="react"
class="green-text pr-2" size='4x'>
</mdb-icon>React
<br>
<mdb-icon fab icon="html5"
class="green-text pr-2" size='4x'>
</mdb-icon>HTML5
<br>
<mdb-icon fab icon="js"
class="green-text pr-2" size='4x'>
</mdb-icon>JS
<br>
<mdb-icon fab icon="mdb"
class="green-text pr-2" size='4x'>
</mdb-icon>MDB
</div>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent { }
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from
'@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MDBBootstrapModule.forRoot(),
FormsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
输出:
例子2:在这个例子中,我们将学习如何在一个按钮中添加图标。
<div id='gfg'>
<h2>GeeksforGeeks</h2>
<h4>Angular MDBootstrap Icons</h4>
<br />
<button type="button" mdbBtn size='sm'
floating="true" color="blue">
Angular<mdb-icon fab icon="angular"
class="green-text pr-2" size='4x'>
</mdb-icon>
</button>
<button type="button" mdbBtn rounded="true"
size="sm" floating="true" size="sm" color="red">
React<mdb-icon fab icon="react"
class="green-text pr-2" size='4x'>
</mdb-icon>
</button>
<button type="button" mdbBtn rounded="true"
floating="true" size="sm" color="green">
JavasScript<mdb-icon fab icon="js"
class="green-text pr-2" size='4x'>
</mdb-icon>
</button>
<br>
<button type="button" mdbBtn rounded="true"
floating="true" size="sm" color="grey">
HTML5<mdb-icon fab icon="html5"
class="green-text pr-2" size='4x'>
</mdb-icon>
</button>
<button type="button" mdbBtn rounded="true"
floating="true" size="sm" color="orange">
MDB<mdb-icon fab icon="mdb"
class="green-text pr-2" size='4x'>
</mdb-icon>
</button>
<button type="button" mdbBtn rounded="true"
floating="true" size="sm" color="warning">
Code<mdb-icon fas icon="code"
class="green-text pr-2" size='4x'>
</mdb-icon>
</button>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent { }
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from
'@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MDBBootstrapModule.forRoot(),
FormsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
输出: