微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular 弹窗 控件

这个控件个人很喜欢,比起primgNG等弹窗组建,这款弹窗可以很轻松的定义自己的样式和布局。

可控参数有:宽度,高度,是否带有关闭图标,基本满足基础弹窗需求。

并且 Title/Content/Footer可以不强制三者并存。

分享图片

 

调用组件方法如下:

<popup-common *ngIf="showPupup" [width]="600" [height]="300" [closebtn]="true" (popupData)="closePopupFn($event)">
        <div class="popup-title">Title</div>
        <div class="popup-content">
            This is the content.
        </div>
        <div class="popup-footer">
            This is the footer.
        </div>
 </popup-common>

 

弹窗组件:

import { Component,OnInit,Input,Output,EventEmitter } from ‘@angular/core‘;


@Component ({
    selector: ‘popup-common‘,template: `<div class="popup-mask">
                    <div class="popup-maskBox">
                        <div class="popup-maskContentBox" [ngStyle]="getStyle()">
                            <ng-content select=".popup-title"></ng-content>
                            <ng-content select=".popup-content"></ng-content>
                            <ng-content select=".popup-footer"></ng-content>
                            <span class="fa fa-close close-icon" *ngIf="closebtn" (click)="closePopupFn()"></span>
                        </div>
                    </div>
                </div>
                `,styles: [`
        .popup-maskContentBox {
            position: relative;
        }
        .close-icon {
            position: absolute;
            right: -15px;
            top: -15px;
            color: #fff;
            background: rgba(0,.5);
            border-radius: 50%;
            font-size: 12px;
            width: 30px;
            height: 30px;
            text-align: center;
            line-height: 30px;
        }
        .close-icon:hover {
            cursor: pointer;
        }
    `]
})

export class PopupCommonComponent implements OnInit {
    @input() width: number;
    @input() height: number;
    @input() showPopup: boolean;
    @input() closebtn: boolean = true;
    @Output() popupData = new EventEmitter();

    ngOnInit(){
        this.width = this.width != undefined ? this.width : 500;
    }

    getStyle(){
        return { width: this.width + ‘px‘,height: this.height + ‘px‘ }
    }

    closePopupFn(){
        this.showPopup = false;
        this.popupData.emit(this.showPopup);
    }

    



}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐