📜  Angular MDBootstrap 警报组件

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

Angular MDBootstrap 警报组件

MDBootstrap是一个基于 Material Design 和 bootstrap 的 Angular UI 库,用于通过其无缝且易于使用的组件制作有吸引力的网页。在本文中,我们将了解如何在 Angular MDBootstap 中使用 Alerts 组件。

警报组件用于为典型的用户操作提供上下文反馈消息,使用特定颜色描述信息的情感权重。

句法:

Content

方法:

  • 从官方网站下载 Angular MDBootstrap。
  • 将文件解压缩到当前工作目录。
  • 使用以下命令在当前项目中安装 npm:
npm install
  • 创建项目文件夹后,即appname ,使用以下命令移动到该文件夹:
cd appname
  • 使用以下命令启动服务器:
ng serve

项目结构:安装完成后如下图所示:

项目结构

示例 1 :这是说明如何在 Angular MDBootstrap 中使用警报组件的基本示例。

app.component.html
    

GeeksforGeeks

    

Angular MDBootstrap Alerts Component

    
    
GeeksforGeeks
    
GeeksforGeeks
    
GeeksforGeeks
    
GeeksforGeeks
    
GeeksforGeeks
    
GeeksforGeeks
    
GeeksforGeeks
    
GeeksforGeeks


app.component.ts
import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{}


app.module.ts
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{}


HTML
    
    
        

GeeksforGeeks

        

Angular MDBootstrap Alerts Component

        
        

            MDBootstrap                 is a Material Design and bootstrap-based                 Angular UI library that is used to make                attractive webpages with its seamless and                 easy-to-use component. It is a popular UI KIT                 for building responsive, mobile-first websites                 and apps.          

    


app.component.ts
import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{}


app.module.ts
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{}


app.component.ts

import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{}

app.module.ts

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{}

输出:

Angular MDBootstrap 警报组件

示例 2:此示例说明了在 Angular MDBootstrap 中添加带有警报链接颜色的警报附加内容。

  • app.component.html:

HTML

    
    
        

GeeksforGeeks

        

Angular MDBootstrap Alerts Component

        
        

            MDBootstrap                 is a Material Design and bootstrap-based                 Angular UI library that is used to make                attractive webpages with its seamless and                 easy-to-use component. It is a popular UI KIT                 for building responsive, mobile-first websites                 and apps.          

    

app.component.ts

import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{}

app.module.ts

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{}

输出:

在 Angular MDBootstrap 中添加警报附加内容

参考: https ://mdbootstrap.com/docs/angular/components/alerts/