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 写的有点繁琐,无意间看到这个框架,觉得挺好用的就开始学习了,但是这个框架上面有很多知识,不是所有的都要学的,故将学习笔记和觉得 ...
随机推荐
- keepalived+nginx双机热备+负载均衡
Reference: http://blog.csdn.net/e421083458/article/details/30092795 keepalived+nginx双机热备+负载均衡 最近因业务扩 ...
- Emacs文件命令
[文件]----------------------------------------C-x C-f 读取文件到Emacs C-x r 只读的方式打开一个文件C-x C-q 清除一个窗口的只读属性 ...
- 4. EM算法-高斯混合模型GMM详细代码实现
1. EM算法-数学基础 2. EM算法-原理详解 3. EM算法-高斯混合模型GMM 4. EM算法-高斯混合模型GMM详细代码实现 5. EM算法-高斯混合模型GMM+Lasso 1. 前言 EM ...
- 基于jQuery仿去哪儿城市选择代码
基于jQuery仿去哪儿城市选择代码.这是一款使用的jQuery城市选择特效代码下载.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class="lin ...
- [EF] 如何在 Entity Framework 中以手动方式设定 Code First 的 Migration 作业
Entity Framework (简称 EF) 发展到现在, 版本已经进入 6.1.0, 距离我写的「在 VS2013 以 Code First 方式建立 EF 资料库」这篇文章已有半年的时间.如果 ...
- 聊聊Google face api
图像处理开源了很多东西,保存下一些基础的东西,以用来follow最新的东西. Google Face API 是什么? Google 的 Face API 用于面部检测,从图片中找出人的面部,以及位置 ...
- flume中HdfsSink参数说明
flume到hdfsSink: type hdfs path 写入hdfs的路径,需要包含文件系统标识,比如:hdfs://namenode/flume/webdata/ 可以使用flume提供的日期 ...
- redis详细配置文件
redis 单机版自己指定配置 #修改为守护模式 daemonize yes #设置进程锁文件 pidfile /usr/local/redis/redis.pid #端口 port 6379 #客户 ...
- python多线程同步机制Semaphore
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Python 线程同步机制:Semaphore "" ...
- java对mongoDB的基本操作 ,游标使用
package com.mongodb.text; import java.net.UnknownHostException; import java.util.List; import org.bs ...