如何在角度2中实现阻止ui的行为
发布时间:2020-12-17 17:21:44 所属栏目:安全 来源:网络整理
导读:如何在角度2中实现块ui( http://malsup.com/jquery/block/#demos)类型的阻止用户交互?请有人帮忙. 解决方法 spinner.ts import {Component} from 'angular2/core';@Component({ selector: 'spinner',styleUrls: ['spinner.css'],//I'm using in modal-backd
如何在角度2中实现块ui(
http://malsup.com/jquery/block/#demos)类型的阻止用户交互?请有人帮忙.
解决方法
spinner.ts
import {Component} from 'angular2/core'; @Component({ selector: 'spinner',styleUrls: ['spinner.css'],//I'm using in modal-backdrop classes from bootstrap template: `<div class="in modal-backdrop spinner-overlay"></div> <div class="spinner-message-container" aria-live="assertive" aria-atomic="true"> <div class="spinner-message" [ngClass]="spinnerMessageClass">{{ state.message }}</div> </div>` }) export class SpinnerComponent { state = { message: 'Please wait...' }; } spinner.css .spinner-overlay { background-color: white; cursor: wait; } .spinner-message-container { position: absolute; top: 35%; left: 0; right: 0; height: 0; text-align: center; z-index: 10001; cursor: wait; } .spinner-message { display: inline-block; text-align: left; background-color: #333; color: #f5f5f5; padding: 20px; border-radius: 4px; font-size: 20px; font-weight: bold; filter: alpha(opacity=100); } spinner.service.ts import {Injectable,DynamicComponentLoader,ApplicationRef,ElementRef,ComponentRef} from 'angular2/core'; import {SpinnerComponent} from './spinner.component'; @Injectable() export class SpinnerService { spinnerComp: ComponentRef; constructor(private componentLoader: DynamicComponentLoader,private appRef: ApplicationRef) { } public start() { let elementRef: ElementRef = this.appRef['_rootComponents'][0].location; return this.startInside(elementRef,null); } public startInside(elementRef: ElementRef,anchorName: string) { let spinnerRef = (!anchorName) ? this.componentLoader.loadNextToLocation(SpinnerComponent,elementRef) : this.componentLoader.loadIntoLocation(SpinnerComponent,elementRef,anchorName); spinnerRef.then((compRef:ComponentRef) => { this.spinnerComp = compRef; }); } public stop() { if (this.spinnerComp) { this.spinnerComp.dispose(); } } } 将微调器服务注入组件.调用开始和停止显示和隐藏. 更新:demo plnkr链接:http://plnkr.co/edit/Y2ocRpbi2ORjbULrguDg 免责声明:我使用一个现有的angular2库作为参考,在我的项目中创建上面的代码.我正在搜索该库,并在找到它时将在此处更新. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |