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 写的有点繁琐,无意间看到这个框架,觉得挺好用的就开始学习了,但是这个框架上面有很多知识,不是所有的都要学的,故将学习笔记和觉得 ...
随机推荐
- C#正则表达式提取HTML中IMG标签的SRC地址
一般来说一个 HTML 文档有很多标签,比如“<html>”.“<body>”.“<table>”等,想把文档中的 img 标签提取出来并不是一件容易的事.由于 i ...
- C#学习笔记(3)——操作sqlserver数据库增删改查
说明(2017-5-25 16:29:35): 1. VS2010,视图->服务器资源管理器->数据连接->右键添加连接->服务器名(本机可以用点)->选择数据库-> ...
- 关于dubbo的provider和consumer都配置timeout超时时间的情况
本文转自:http://blog.csdn.net/lkforce/article/details/54380201 前言 在dubbo的provider和consumer的配置文件中,如果都配置了t ...
- 快速排序,一个爱情故事-java版
public static void myquicksort(int[] ages,int girl,int boy){ //这是一个站在数组两端,追求完美爱情的故事 //年龄不匹配的不要 //第0步 ...
- The type name 'IComponentConnector' could not be found in the namespace 'System.Windows.Markup'
场景:Visual Studio写WPF项目时,想要生成XML文件,默认的WPF项目没有引入System.XML这个dll.在[解决方案资源管理器——引用]右键添加了System.XML引用后,运行项 ...
- 【WPF】软件更新程序的设计思路
目标:客户端程序在启动时,自动联网检查服务端是否有新的版本,有则提示用户更新客户端. 思路: 1.打开Visual Studio,在主体程序的解决方案下再新建一个叫自动更新程序的项目.主体程序的目录是 ...
- 【Unity Shader】五、Shader纹理映射,及纹理的缩放和偏移
将漫反射的颜色改为从纹理贴图中获取,逐像素计算. Shader "Custom/11-Texture" { // 纹理贴图,BlinnPhong光照模型 Properties{ / ...
- C语言 · 瓷砖铺放
算法训练 瓷砖铺放 时间限制:1.0s 内存限制:512.0MB 锦囊1 递归或递推. 问题描述 有一长度为N(1<=N<=10)的地板,给定两种不同瓷砖:一种长 ...
- Tomcat配置JMX远程监控(Windown7 Linxu)
一:Window7下配置方式. 1.配置catalina.bat 在第一行加入下面配置 注意下面这些配置要在一行,注意包含空格. set JAVA_OPTS=-Dcom.sun.management. ...
- jquery笔记一——小问题+小技巧
1.table行单击选中radio(传说中input[type=radio]比input:radio要快) <tr class="rowSelect"> <td& ...