BootstrapConfirm
Confirm service and directive with bootstrap dialog
Installation
npm install @kovalenko/bootstrap-confirm
Directive
Selector: (confirm)
Properties
Name | Description |
---|---|
@Input() confirmMessage: string |
Confirm message |
@Input() confirmOk: string |
Ok button text |
@Input() confirmCancel: string |
Cancel button text |
@Output() confirm: EventEmitter<any> |
This will callback if Ok button clicked |
Service
ConfirmService
Calls confirmation dialog programmatically
Methods
confirm: Promise<boolean> |
|
---|---|
Action confirm | |
Arguments | |
confirmMessage: string |
Confirm message |
confirmOk?: string |
Ok button text |
confirmCancel?: string |
Cancel button text |
config?: MatDialogConfig |
Override dialog config |
setDefaults: void |
|
---|---|
Set default values | |
Параметры | |
ok: string |
Ok button text |
cancel: string |
Cancel button text |
Usage
First, import the BootstrapConfirmModule to your module:
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {BootstrapConfirmModule, BootstrapConfirmConfig} from '@kovalenko/bootstrap-confirm';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppComponent} from './app';
const bootstrapConfirmConfig: BootstrapConfirmConfig = {
ok: 'Ok',
cancel: 'Cancel',
};
@NgModule({
imports: [
BrowserModule,
BootstrapConfirmModule.config(bootstrapConfirmConfig)
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {
}
platformBrowserDynamic().bootstrapModule(AppModule);
Confirmation via directive
import { Component } from '@angular/core';
@Component({
selector: 'app',
template: `
<button (confirm)="callback()" [confirmMessage]="message">Click</button>
`,
})
export class AppComponent {
message = 'Confirm action';
callback() {
console.log('confirmed');
}
}
Confirmation via service
import {Component} from '@angular/core';
import {ConfirmService} from '@kovalenko/bootstrap-confirm';
@Component({
selector: 'app',
template: `
<button (click)="action()">Click</button>
`,
})
export class AppComponent {
constructor(private confirmService: ConfirmService) { }
async action() {
if (await this.confirmService.confirm('Confirm action')) {
console.log('confirmed');
}
}
}
License
MIT