NPM
npm install ngx.superlayer
Release notes
- 2018/7/4——
- rename from "angular2-layer" to "ngx.superlayer"
- upgrade to support angular 6
- 2017/4/21——rewrite totally by angular 4, it is more convenient to use
- 2017/1/14——modify LayerConfig; update angular to 4.0
- 2017/1/14——add LayerConfig.imports and LayerConfig.declarations
- 2017/1/12——passing data to the component by LayerConfig.data
Classes
NgxLayer
可以把NgLayer 看作是一个弹出层的factory。NgLayer能够生成五种类型的弹层,分别对应五个方法(参数具体含义请看代码注释):
dialog(config:LayerConfig):NgxLayerRef
,open a dialog windowalert(config:LayerConfig):NgxLayerRef
,open a alert windowconfirm(config:LayerConfig):NgxLayerRef
,open a confirm windowtip(config:LayerConfig):NgxLayerRef
,open a message layerloading(config:LayerConfig):NgxLayerRef
,open a loading layer
NgxLayerRef
NgxLayerRef 是对弹出层的一个引用,通过这个引用,可以对弹出层进行操作或者指定事件的回调函数 包含如下方法(参数具体含义请看代码注释):
close():void
,destory the layershowCloseBtn(show:boolean)
,show close button or notsetTitle(title:string):NgxLayerRef
,update dialog title. for dialog onlysetMessage(message:string):NgxLayerRef
,update message of layersetOkText(ok:string):NgxLayerRef
,update "ok" button text, for alert layer or confirm layersetCancelText(cancel:string):NgxLayerRef
,update "cancel" button text, for confirm layer onlysetOnClose(callBack:()=>boolean):NgxLayerRef
,if the callBack return ture, the layer will be closedok(okCallback:()=>boolean):NgxLayerRef
,okCallback called on 'ok' button click. for alert layer or confirm layercancel(cancelCallback:()=>boolean):NgxLayerRef
,cancelCallback called on "cancel" button click. for confirm layer only
LayerConfig
LayerConfig 是弹出层的配置类
parent:any
,the new component will be a child of parent, if parent is null, new component will be a root component of application. valid only for dialog leyerdialogComponent:any
,dialog dialog body Componentdata:Object
,datas pass to dialog componenttitle:string
,dialog title valid only for dialog leyercloseAble:boolean
,show close button or not. valid only for dialog leyermessage:string
,message type of tip layer. valid for alert, confirm, tip, loading leyerokText:string
,text of "ok" button. valid for alert or confirm leyercancelText:string
,text of "cancel" button.valid only for confirm leyeralign:string
,position of the layer("top", "center", "bottom"), default to "top" valid only for loading or tip leyerisModal:boolean
,modal window or not valid only for loading leyertipDuration:number
,layer will be automatic closed after duration(ms) valid only for tip leyerinSelector:string
,defined a popup animation by a class selector valid for all type leyer. existing options: rollIn, fallDown, fadeInDown, runIn, bounceIn, platIn, dropDown, vanishIn, spaceIn, jelly, fadeInUpoutSelector:string
,defined a closeing animation by a class selector valid for all type leyer. existing options: rollOut, fadeOutDown, bounceOut, vanishOut, spaceOut, boingOut, fadeOutDown
Usage & demo
talk is cheape, show you my code
step 1
import css
step 2
use it
import {Component, NgModule} from '@angular/core'import {BrowserModule} from '@angular/platform-browser';import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';import {NgxLayer, NgxLayerRef, NgxLayerComponent} from "ngx.superlayer"; @Component({ selector: '.app', templateUrl: 'temp/app.html', providers: [NgxLayer]})export class AppComponent { constructor(private ly:NgxLayer) {} config:any = { inSelector:"fallDown", outSelector:"rollOut", title:"angular2 layer", align:"top", parent: this, dialogComponent:DialogComponent, closeAble: false } dialog(){ this.ly.dialog(this.config); } alert(){ this.ly.alert(this.config); } confirm(){ this.ly.confirm(this.config); } loading(){ let tip = this.ly.loading(this.config); setTimeout(()=>{tip.close();}, 2000) } tip(){ this.ly.tip(this.config); }} /*component for dialog*/@Component({ selector: '.dialog', templateUrl: 'temp/dialog.html'})export class DialogComponent { data = "angular2 layer"; constructor(private ly:NgxLayerRef, private l:NgxLayer) {} setTitle(){this.ly.setTitle("Ngx Layer Title");} close(){this.ly.close();} showCloseBtn(){this.ly.showCloseBtn(true)}; showData(){alert(this.data)};} @NgModule({ imports: [BrowserModule], entryComponents:[NgxLayerComponent, DialogComponent], declarations: [AppComponent, NgxLayerComponent, DialogComponent], bootstrap: [AppComponent]})class AppModule {}platformBrowserDynamic().bootstrapModule(AppModule);
index.html
angular2 playground loaing...
app.html
template of app Component
dialogconfirmalertloadingtip
dialog.html
template of dialog Component
Ngx Layer Angular2 弹层插件,灵活,简单,丰富,优美 setTitle showCloseBtn showData
Live demo
code is cheape, here is the live demo