ngx-bootstrap学习笔记(一)-popover
前言
这月做了个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学习笔记(一)-popover的更多相关文章
- Bootstrap~学习笔记索引
回到占占推荐博客索引 bootstrap已经用了有段时间了,感觉在使用上还是比较容易接受的,在开发人员用起来上,也还好,不用考虑它的兼容性,手机,平台,PC都可以有效的兼容. bootstrap官方a ...
- Bootstrap学习笔记(二) 表单
在Bootstrap学习笔记(一) 排版的基础上继续学习Bootstrap的表单,编辑器及head内代码不变. 3-1 基础表单 单中常见的元素主要包括:文本输入框.下拉选择框.单选按钮.复选按钮.文 ...
- bootstrap学习笔记之为导航条添加标题、二级菜单及状态 http://www.imooc.com/code/3120
为导航条添加标题.二级菜单及状态 加入导航条标题 在Web页面制作中,常常在菜单前面都会有一个标题(文字字号比其它文字稍大一些),其实在Bootstrap框架也为大家做了这方面考虑,其通过" ...
- bootstrap学习笔记之基础导航条 http://www.imooc.com/code/3111
基础导航条 在Bootstrap框中,导航条和导航从外观上差别不是太多,但在实际使用中导航条要比导航复杂得多.我们先来看导航条中最基础的一个--基础导航条. 使用方法: 在制作一个基础导航条时,主要分 ...
- Bootstrap学习笔记-布局
Bootstrap学习笔记-布局 默认是响应式布局,就是你在改变页面的时候也不会出现乱的现象. <html><head> <meta charset="utf- ...
- Bootstrap学习笔记博客
本片博客用于记录之后要用到Bootstrap的学习笔记 概括: Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架.Bootstrap 是基于 HTML.CSS.JAVASC ...
- bootstrap学习笔记--bootstrap安装环境
Bootstrap 安装是非常容易的.此文是本人的学习汇总,便于以后查询学习,同时也希望给大家带来帮助. 下载 Bootstrap 您可以从 http://getbootstrap.com/ 上下载 ...
- Bootstrap学习笔记系列1-------Bootstrap网格系统
Bootstrap网格系统 学习笔记 [TOC] 简单网格 先上代码再解释 <!DOCTYPE html> <html> <head> <title>B ...
- bootstrap 学习笔记(1)---介绍bootstrap和栅格系统
学习前端许久,对于布置框架和响应浏览器用html 和javascript 写的有点繁琐,无意间看到这个框架,觉得挺好用的就开始学习了,但是这个框架上面有很多知识,不是所有的都要学的,故将学习笔记和觉得 ...
随机推荐
- LeetCode: Palindrome 回文相关题目
LeetCode: Palindrome 回文相关题目汇总 LeetCode: Palindrome Partitioning 解题报告 LeetCode: Palindrome Partitioni ...
- Excel中功能清单转Project任务
接:http://www.cnblogs.com/vipsoft/p/8495220.html 1.在E列输入公式: =IF(LEN(A2)>1,1,IF(LEN(B2)>1,2,IF(L ...
- WebSphere ILOG JRules 规则引擎运行模式简介
WebSphere ILOG JRules 规则引擎运行模式简介 引言 作为 JRules 的核心组件,规则引擎决定了在规则集的执行过程中,哪些业务规则会被执行,以及以何种顺序执行.理解并合理选择规则 ...
- putty配色备份
[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Solarized%20Dark] "Colour0"="1 ...
- Python 实现多元线性回归预测
一.二元输入特征线性回归 测试数据为:ex1data2.txt ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ...
- Java 9中的 9个 新特性
Java 9 中的 9个 新特性 java 7 2011发布,Java 8 2014发布,java9发布于2017年9月21日. 你可能已经听说过 Java 9 的模块系统,但是这个新版本还有许多其它 ...
- UI设计, 弹出对话框 设计(区分强调按钮和普通按钮,给用户一个 正向建议的强调按钮)
在UI设计时,经常会需要 设计 弹出对话框,以下是个样式设计: 0.标准对话框 说明 Title space : 标题区 contents space : 内容区 function space: 功能 ...
- mysql lower_case_table_names 区分表名大小写设置
Command-Line Format --lower-case-table-names[=#] System Variable Name lower_case_table_names Variabl ...
- float right
很多时候,"更多"会和title在一行显示,放在右边 我们可能马上想到这样做: h1 a{ float: right; } <h1>这是个title<a>更 ...
- PCL深度图像(2)
(1)点云到深度图与可视化的实现 区分点云与深度图本质的区别 1.深度图像也叫距离影像,是指将从图像采集器到场景中各点的距离(深度)值作为像素值的图像.获取方法有:激光雷达深度成像法.计算机立体视觉成 ...