Home >>Ngx Bootstrap Tutorial >Ngx Bootstrap Popover

Ngx Bootstrap Popover

Ngx Bootstrap Popover

A small overlay component is provided by the ngx-bootstrap popover component to provide small component information.

PopoverDirective

selector

  • popover

Inputs

  • adaptivePosition-Boolean, set the adaptive position to disable.
  • container − string, A selector indicating the element to which the popover should be appended.
  • containerClass − string, class Css for popover containers
  • delay − number, Delay before the tooltip is shown
  • isOpen- Boolean, returns whether the popover is currently displayed or not.
  • outsideClick − Boolean, Outside click close popover, default: false
  • placement− "top" | "bottom" | "left" | "right" | "auto" | "top left" | "top right" | "top right" | "bottom right" | "bottom right" | "bottom left" | "left bottom" | "left top" | "popover placement." Accepts: "top", "bottom", "left" and "right"
  • popover − Content to be shown as popover, string | TemplateRef.
  • popoverContext −Context to be used if popover is a template.
  • PopoverTitle − string, Popover title.
  • triggers − String, Defines events to trigger. A space-separated list of event names is supported.

Outputs

  • onHidden -When the popover is hidden, onHidden emits an event.
  • onShown-Emits an occurrence when the popover is shown.

Methods

  • setAriaDescribedBy() − Set the aria-describedBy attribute to the element directive and set the popover id.
  • show() − Opens the popover element. This is considered a "manual" popover triggering process.
  • hide()- closes popover of an element. This is considered a "manual" popover triggering process.
  • toggle()-Toggles the popover for an element. This is considered a "manual" popover triggering process.

Example

We have to update app.module.ts to use PopoverModule and PopoverConfig in the ngx-bootstrap Pagination chapter as we are going to use a popover.

To use PopoverModule and PopoverConfig, update app.module.ts.

app.module.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 { }

Update test.component.html to use the modal.

test.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>

Update test.component.ts for corresponding variables and methods.

test.component.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 {
   }
}

Build and Serve

Run the following command to start the angular server.

ng serve

No Sidebar ads