ngx-bootstrap学习笔记(一)-popover
来源:互联网 发布:电脑桌面工作提醒软件 编辑:程序博客网 时间:2024/06/01 14:41
前言
这月做了个ng2模块,其中有个校验功能,当校验不通过时给出提示,项目中使用jQuery实现,今天才发现ngx-bootstrap已经有现成功能了,且可封装成通用组件放入shareModule,使用方便。故记录如下。
安装
npm install ngx-bootstrap --save
引入模块
import {PopoverModule} from 'ngx-bootstrap/';@NgModule({ declarations: [XxxComponent...], imports: [ BrowserModule, PopoverModule.forRoot(), FormsModule ], providers: [XxxService...], bootstrap: [XxxComponent]})
封装组件
popover.component.ts
import {Component, ViewChild} from '@angular/core';import {PopoverDirective} from 'ngx-bootstrap';@Component({ selector: 'nepsd-popover', templateUrl: './popover.component.html', styleUrls: ['./popover.component.css']})export class PopoverComponent { @ViewChild('pop') popover: PopoverDirective;}
popover.component.html
<span popover #pop="bs-popover"> <ng-content></ng-content></span>
popover.component.css
:host > > > .popover { background-color: #FCFCFC; } :host > > > .popover > .arrow:after { border-top-color: #FCFCFC; }
其他组件引用
app.component.ts
import {Component, ViewChild} from '@angular/core';import {PopoverComponent} from './popover/popover.component';@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})export class AppComponent { tip: string; @ViewChild('pop') popoverComponent: PopoverComponent; validInput() { let valid = Math.random() > 0.5; if (!valid) { /**pop config*/ this.popoverComponent.popover.popoverTitle = undefined; this.popoverComponent.popover.popover = this.tip; this.popHover(); } } private popHover(timeout?: number) { timeout = timeout ? timeout : 1000; this.popoverComponent.popover.show(); setTimeout(() => { this.popoverComponent.popover.hide(); }, timeout); }}
app.component.html
<div style="margin-top: 100px"> <nepsd-popover #pop> <input [(ngModel)]="tip" (change)="validInput()" (blur)="popHover()"> </nepsd-popover></div>
效果
参考
ngx-bootstrap
阅读全文
0 0
- ngx-bootstrap学习笔记(一)-popover
- ngx-bootstrap解析(一)
- Boostrap学习笔记一: popover用法
- bootstrap学习笔记一
- BootStrap学习笔记一
- bootstrap学习笔记(一)
- bootstrap学习笔记(一)
- Bootstrap学习总结笔记(19)-- 基本插件之Popover提示框
- Bootstrap学习笔记(一)
- bootstrap 学习笔记(一)
- Bootstrap学习笔记(一) 排版
- BootStrap学习笔记(一)
- Bootstrap学习笔记(一)
- Bootstrap学习笔记(一)
- Bootstrap 学习笔记(一)
- BootStrap ToolTip , popover
- bootstrap popover稍微修改
- bootstrap popover简单用法
- CDN远程库
- 栈及栈的应用(括号匹配和逆波兰表达式)
- python学习笔记 第十二章
- Sublime Text 3 Build 3155 & 3156 License
- Class.forName()用法详解
- ngx-bootstrap学习笔记(一)-popover
- 二叉树--uva122 结构体+指针解法
- log4j
- 个人简介
- Effective STL学习笔记-条款44
- 开始机器学习
- 微服务架构适用场景分析
- 云服务模式:SaaS、PaaS和IaaS
- 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)