- Ngx-Bootstrap 教程
- Ngx-Bootstrap - 主页
- Ngx-Bootstrap - 概述
- Ngx-Bootstrap - 环境设置
- Ngx-Bootstrap - 手风琴
- Ngx-Bootstrap - 警报
- Ngx-Bootstrap - 按钮
- Ngx-Bootstrap - 轮播
- Ngx-Bootstrap - 折叠
- Ngx-Bootstrap - DatePicker
- Ngx-Bootstrap - 下拉菜单
- Ngx-Bootstrap - 模态框
- Ngx-Bootstrap - 分页
- Ngx-Bootstrap - 弹出窗口
- Ngx-Bootstrap - 进度条
- Ngx-Bootstrap - 评级
- Ngx-Bootstrap - 可排序
- Ngx-Bootstrap - 选项卡
- Ngx-Bootstrap - 时间选择器
- Ngx-Bootstrap - 工具提示
- Ngx-Bootstrap - Typeahead
- Ngx-Bootstrap 有用资源
- Ngx-Bootstrap - 快速指南
- Ngx-Bootstrap - 有用的资源
- Ngx-Bootstrap - 讨论
Ngx-Bootstrap - 弹出窗口
ngx-bootstrap popover 组件提供了一个小的覆盖组件来提供有关组件的小信息。
弹出指令
选择器
弹出窗口
输入
AdaptivePosition - 布尔值,设置禁用自适应位置。
容器- 字符串,指定弹出框应附加到的元素的选择器。
containerClass - 字符串,弹出容器的 Css 类
延迟- 数字,显示工具提示之前的延迟
isOpen - 布尔值,返回当前是否显示弹出窗口
externalClick - 布尔值,在外部单击时关闭弹出窗口,默认值: false
位置- “顶部”| “底部”| “左”| “对”| “自动”| “左上角” | “右上角” | “右上”| “右下”| “右下角” | “左下角” | “左下”| “左上”,弹出框的位置。接受:“上”、“下”、“左”、“右”。
弹出窗口- 字符串 | TemplateRef<any>,要显示为弹出窗口的内容。
popoverContext - 任意,如果 popover 是模板则使用的上下文。
popoverTitle - 字符串,弹出窗口的标题。
触发器- 字符串,指定应触发的事件。支持空格分隔的事件名称列表。
输出
onHidden - 隐藏弹出窗口时发出事件。
onShown - 显示弹出窗口时发出事件。
方法
setAriaDescribedBy() - 为元素指令设置属性 aria-scribedBy 并为弹出窗口设置 id。
show() - 打开元素的弹出窗口。这被认为是弹出窗口的“手动”触发。
hide() - 关闭元素的弹出窗口。这被认为是弹出窗口的“手动”触发。
toggle() - 切换元素的弹出框。这被认为是弹出窗口的“手动”触发。
例子
由于我们将使用弹出窗口,因此我们必须更新ngx-bootstrap 分页章节中使用的 app.module.ts 以使用PopoverModule和PopoverConfig。
更新 app.module.ts 以使用 PopoverModule 和 PopoverConfig。
应用程序模块.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TestComponent } from './test/test.component';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { AlertModule,AlertConfig } from 'ngx-bootstrap/alert';
import { ButtonsModule } from 'ngx-bootstrap/buttons';
import { FormsModule } from '@angular/forms';
import { CarouselModule } from 'ngx-bootstrap/carousel';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import { BsDatepickerModule, BsDatepickerConfig } from 'ngx-bootstrap/datepicker';
import { BsDropdownModule,BsDropdownConfig } from 'ngx-bootstrap/dropdown';
import { PaginationModule,PaginationConfig } from 'ngx-bootstrap/pagination';
import { PopoverModule, PopoverConfig } from 'ngx-bootstrap/popover';
@NgModule({
declarations: [
AppComponent,
TestComponent
],
imports: [
BrowserAnimationsModule,
BrowserModule,
AccordionModule,
AlertModule,
ButtonsModule,
FormsModule,
CarouselModule,
CollapseModule,
BsDatepickerModule.forRoot(),
BsDropdownModule,
ModalModule,
PaginationModule,
PopoverModule
],
providers: [AlertConfig,
BsDatepickerConfig,
BsDropdownConfig,
BsModalService,
PaginationConfig],
bootstrap: [AppComponent]
})
export class AppModule { }
更新 test.component.html 以使用模式。
测试.component.html
<button type="button" class="btn btn-default btn-primary" popover="Welcome to Tutorialspoint." [outsideClick]="true"> Default Popover </button> <button type="button" class="btn btn-default btn-primary" popover="Welcome to Tutorialspoint." popoverTitle="Tutorialspoint" [outsideClick]="true" placement="right"> Right Aligned popover </button>
更新 test.component.ts 中相应的变量和方法。
测试组件.ts
import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { PageChangedEvent } from 'ngx-bootstrap/pagination';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
constructor() {}
ngOnInit(): void {
}
}
构建和服务
运行以下命令启动角度服务器。
ng serve
服务器启动并运行后。打开http://localhost:4200。单击“打开模式”按钮并验证以下输出。
