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 写的有点繁琐,无意间看到这个框架,觉得挺好用的就开始学习了,但是这个框架上面有很多知识,不是所有的都要学的,故将学习笔记和觉得 ...
随机推荐
- HttpClient request payload post请求
RequestEntity entity = new StringRequestEntity(str, "text/html", "utf-8"); post. ...
- Server.MapPath 出现未将对象引用设置到对象的实例
此文仅在于使遇到相似问题的朋友能少走弯路 asp.net中我用一个页面的cs文件调用一个自定义类,这个自定义类再调用 System.Web.HttpContext.Current.Server.Map ...
- 基于jQuery滑动分步式进度导航条代码
分享一款基于jQuery滑动分步式进度导航条代码.这是一款基于jquery实现的网站注册动态步骤导航条代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div id=& ...
- 前端常用功能记录(三)—datatables表格初始化(转)
数据源 我经常使用的有两种,一种是JavaScript 中的数组,通过在初始化对象中传递一个名为 aaData 的数组,同样可以提供表格数据,前缀 aa 说明这是一个数组的数组,外层的数组表示表格的行 ...
- Linux下架构高可用性网络----HA+LB+lvs
实验总拓扑: IP规划: Director1: eth0 192.168.10.136/28 eth1 192.168.11.2/24 Director2: eth ...
- drupal 内容类型
一.drupal核心下载 https://drupal.org/download 3二.下载中文语言包 https://localize.drupal.org 图1,图2 也可以直接点击:https: ...
- hbase源码系列(十)HLog与日志恢复
HLog概述 hbase在写入数据之前会先写入MemStore,成功了再写入HLog,当MemStore的数据丢失的时候,还可以用HLog的数据来进行恢复,下面先看看HLog的图. 旧版的HLog是实 ...
- PHP开发工程师-技能树
参考进阶-PHP程序员的技术成长规划-http://blog.csdn.net/heiyeshuwu/article/details/40098043 LNMP / LAMP 环境搭建(单组件安装,非 ...
- C#/.NET 学习之路——从入门到放弃
原文链接地址:http://blog.liuhaoyang.me/dotnet/2016/11/25/csharp-books/ 向架构师大步迈进的书单 C# 入门 <C# 本质论> &l ...
- Writing a Reusable Custom Control in WPF
In my previous post, I have already defined how you can inherit from an existing control and define ...