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 写的有点繁琐,无意间看到这个框架,觉得挺好用的就开始学习了,但是这个框架上面有很多知识,不是所有的都要学的,故将学习笔记和觉得 ...
随机推荐
- python解析XML笔记(etree)
近期梳理Weblogic数据源,数据源较多,但是每一个数据源在weblogic中是xml方式存在,所以想到批量解析xml,把数据放到数据库后来解决. 需要的数据源信息: WEBLOGIC_HOSTJD ...
- 初步理解Python进程的信号通讯
Reference: http://www.jb51.net/article/63787.htm 信号的概念 信号(signal)-- 进程之间通讯的方式,是一种软件中断.一个进程一旦接收到信 ...
- iOS手机号,身份证,车牌号正则表达式
1.手机号判断,根据维基百科2016年6月修订的段号判断 是否是手机号 /** 手机号码 13[0-9],14[5|7|9],15[0-3],15[5-9],17[0|1|3|5|6|8],18[0- ...
- [转]Spring MVC 教程,快速入门,深入分析
原文地址:http://elf8848.iteye.com/blog/875830 目录 一.前言 二.spring mvc 核心类与接口 三.spring mvc 核心流程图 四.spring mv ...
- Go语言学习(四)经常使用类型介绍
1.布尔类型 var v1 bool v1 = true; v2 := (1==2) // v2也会被推导为bool类型 2.整型 类 型 长度(字节) 值 范 围 int8 1 128 ~ 12 ...
- WPF重写Button样式
首先指定OverridesDefaultStyle属性为True: 然后添加样式: 重写ControlTemplate: <Window.Resources> <Style x:Ke ...
- (转) Hadoop1.2.1安装
环境:ubuntu13 使用的用户为普通用户.如:用户ru jdk安装略 1.安装ssh (1) sudo apt-get install openssh-server (2)配置ssh面密码登录 $ ...
- C++函数调用时的参数传递-3中传递方式
参数传递即实参向形参传递信息,使形参获得对应的存储空间及初值,C++中函数传递主要有3种方式: 1.按值传递. 以按值传递方式进行参数传递的过程为:首先计算出实参的值,然后给它所对应的形参变量分配存储 ...
- swing自定义border
public class MyBorder extends AbstractBorder { private static final long serialVersionUID = 1L; priv ...
- jquery-仿flash的一个导航栏特效
演示地址:http://itxiaoming.sinaapp.com/demo05/demo.html <html> <head> <meta http-equiv=&q ...