Angular PrimeNG消息可关闭

Angular PrimeNG消息可关闭

Angular PrimeNG是一个开源框架,它有丰富的原生Angular UI组件,可以用来做很好的造型,这个框架用来做响应式网站,非常方便。在这篇文章中,我们将看到如何在Angular PrimeNG中使用Messages Closable。我们还将了解在代码中使用的属性和它们的语法。

信息 “组件用于显示具有特别严重性的信息。由于消息在默认情况下可以被关闭,所以在右上角可以看到一个关闭符号。使用[closable]="false"属性,我们可以使可关闭图标不活动。

语法:

<p-messages 
        [closable]="false" 
        [(value)]="...">
</p-messages>

Angular PrimeNG消息可关闭的属性:

  • value。它是一个要显示的信息数组。它是数组的数据类型,默认值是null
  • closable。它定义了消息框是否可以通过点击图标关闭。它是布尔数据类型,默认值是true

创建Angular应用程序和模块安装。

第1步:使用以下命令创建一个Angular应用程序。

ng new appname

第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。

cd appname

第3步在你给定的目录中安装PrimeNG。

npm install primeng --save
npm install primeicons --save

项目结构:它将看起来像如下。

Angular PrimeNG消息可关闭

  • 运行下面的命令可以看到输出。
ng serve --open

例子1:下面是说明使用Angular PrimeNG Messages Closable的例子代码。

<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Message Closable</h5>
  
    <p-messages
          [closable]="false"
          [(value)]="gfg"> 
    </p-messages>
</div>
import { Component } from "@angular/core";
import { Message } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  gfg: Message[];
  
  ngOnInit() {
    this.gfg = [
      {
        severity: "success",
        summary: "Geek-Success",
        detail: "This is a success Geek",
      },
      {
        severity: "info",
        summary: "Geek-Info",
        detail: "This is a info Geek",
      },
    ];
  }
}
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import {MessagesModule} from 'primeng/messages';
  
@NgModule({
  imports: [
    BrowserAnimationsModule,
    MessagesModule,
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule{}

输出:

Angular PrimeNG消息可关闭

例子2:下面是另一个例子,说明了Angular PrimeNG Messages Closable,通过将[closable]属性指定为true。

<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Message Closable</h5>
  
    <p-messages
          [closable]="true"
          [(value)]="gfg"> 
    </p-messages>
</div>
import { Component } from "@angular/core";
import { Message } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  gfg: Message[];
  
  ngOnInit() {
    this.gfg = [
      {
        severity: "warn",
        summary: "Geek-Warn",
        detail: "This is a warn Geek",
      },
      {
        severity: "error",
        summary: "Geek-Error",
        detail: "This is a error Geek",
      },
    ];
  }
}
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import {MessagesModule} from 'primeng/messages';
  
@NgModule({
  imports: [
    BrowserAnimationsModule,
    MessagesModule,
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
  
export class AppModule {}

输出:

Angular PrimeNG消息可关闭

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程