1.0.1 • Published 3 years ago
ngx-base-modal
Licence
—
Version
1.0.1
Deps
13
Size
33 kB
Vulns
23
Weekly
0
NgxBaseModal
The ngx-base-modal is a library that provides a base component to assist in creating modals.
Dependencies
Having the libraries installed:
Installing NgxBaseModal
npm i ngx-base-modal
Usage
To use ngx-base-modal in your project, follow these steps:
Import the ModalModule from ngx-base-modal.
example-modal.module.ts
import {ModalModule} form 'ngx-base-modal';
@NgModule({
imports: [
...
ModalModule
...
]
})
export class ExampleModalModule {}
Modal structure
example-modal.component.ts
import { Component } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { BaseModal } from 'ngx-modal-base';
@Component({
selector: 'app-example-modal',
template: ´
<ngx-modal>
<ngx-modal-header [title]="title" (closeEventEmitter)="close()" />
<ngx-modal-body>
Modal Body
</ngx-modal-body>
<ngx-modal-footer>
<button class="btn btn-secondary" (click)="close()">
Cancelar
</button>
<button class="btn btn-primary" (click)="close()">
Confirmar
</button>
</ngx-modal-footer>
</ngx-modal>
´,
styleUrls: ['./example-modal.component.scss']
})
export class ExampleModalComponent extends BaseModal {
constructor(
_bsModalRef: BsModalRef
) {
super(_bsModalRef);
}
}
Import the ExampleModalModule
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ModalModule } from 'ngx-bootstrap/modal';
import { AppComponent } from './app.component';
import { ExampleModalModule } from './components/example-modal/example-modal.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ModalModule.forChild(),
ExampleModalModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Open the modal
app.component.ts
import { Component } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { ExampleModalComponent } from './components/example-modal/example-modal.component';
@Component({
selector: 'demo-root',
template:´
<main class="w-100 vh-100 d-flex justify-content-center align-items-center">
<button class="btn btn-primary" (click)="openModal()">Open Modal</button>
</main>
´,
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'example-modal';
constructor(
private __bsModalService: BsModalService
) { }
openModal() {
this.__bsModalService.show(ExampleModalComponent, {
initialState: {
title: 'Modal Title'
},
class: 'modal-dialog-centered modal-lg ',
ignoreBackdropClick: true
});
}
}
License
This project is licensed under the MIT License. Please refer to the LICENSE file for more details.