PrimeNG安装使用

PrimeNG是Angular2的一个富客户端组件,可以独立于Bootstrap单独使用,也可以结合Bootstrap共同使用。

官方上只有例子的介绍,并没找到个类似入门教程一类的资料,这里自己结合网上搜到的资料整理一份入门资料。

官网网址:https://www.primefaces.org/primeng/

我使用angular-cli生成项目

NewImage

需要安装的包有primeng、font-awesome

@angular/animations看你项目之前是否安装过,如果没有则需要安装,否则会报错

ERROR in ./~/primeng/components/panel/panel.js
Module not found: Error: Can't resolve '@angular/animations' in '/Users/xuwen/workspace/angular2/primengtest/node_modules/primeng/components/panel'
 @ ./~/primeng/components/panel/panel.js 15:19-49
 @ ./~/primeng/primeng.js
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:4200 ./src/main.ts

NewImage

再接下来就可以使用PrimeNG组件了

首先来配置css文件(选择我们需要的风格bootstrap、omega等)

"styles": [
    "styles.css",
    "../node_modules/primeng/resources/themes/bootstrap/theme.css",
    "../node_modules/primeng/resources/primeng.min.css",
    "../node_modules/font-awesome/css/font-awesome.css"
],

添加所需要的模块,在app.module.ts添加

app.module.ts代码

import { BrowserModule }  from  '@angular/platform-browser';
import { BrowserAnimationsModule }  from  '@angular/platform-browser/animations';
import { NgModule }  from  '@angular/core';
import { FormsModule }  from  '@angular/forms';
import { HttpModule }  from  '@angular/http';

import { ConfirmDialogModule }  from  'primeng/primeng';
import { GrowlModule }  from  'primeng/primeng';

import { AppComponent }  from  './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    ConfirmDialogModule,
    BrowserAnimationsModule,
    GrowlModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export  class AppModule { }

app.component.ts代码

import { Component }  from  '@angular/core';

import { Message }  from  'primeng/primeng';
import { ConfirmationService }  from  'primeng/primeng';

@Component({
  selector:  'app-root',
  templateUrl:  './app.component.html',
  styleUrls: [ './app.component.css'],
  providers: [ConfirmationService]
})
export  class AppComponent {

  msgs: Message[] = [];

   constructor( private confirmationService: ConfirmationService) { }

  confirm1() {
     this.confirmationService.confirm({
      message:  'Are you sure that you want to perform this action?',
      accept: ()  => {
         this.msgs = [];
         this.msgs.push({ severity:  'info', summary:  'Confirmed', detail:  'You have accepted' });
      }
    });
  }

  confirm2() {
     this.confirmationService.confirm({
      message:  'Do you want to delete this record?',
      header:  'Delete Confirmation',
      icon:  'fa fa-trash',
      accept: ()  => {
         this.msgs = [];
         this.msgs.push({ severity:  'info', summary:  'Confirmed', detail:  'Record deleted' });
      }
    });
  }
}

app.component.html代码

< p-growl [ value]= "msgs" ></ p-growl >
    
< p-confirmDialog  width= "425" ></ p-confirmDialog >

< button  type= "button" ( click)= "confirm1()"  pButton  icon= "fa-check"  label= "Confirm" ></ button >

< button  type= "button" ( click)= "confirm2()"  pButton  icon= "fa-trash"  label= "Delete" ></ button >

最终效果

NewImage

NewImage

转载于:https://www.cnblogs.com/bh4lm/p/6649796.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值