npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-bs-modals-creator

v6.0.8

Published

Utility to dinamically create Bootstrap 4 modals using Angular (>= 6)

Downloads

18

Readme

This library is DEPRECATED. Use ngx-boostrap instead.

Intro

ngx-bs-modals-creator is a utility that helps developers to show Boostrap 4.* modals using Angular. Bootstrap modals works better if you append them as close as you can to the body element. Given a Component Type, this library let you instantiate a modal from code (without declaring it in the template) and it automatically appends the component to a specific modal-container. You have the control over the modals-container, so you can put it where ever you want. As said, it is suggested to put it as close as you can to the body element.

If you have any suggestion please contact us. Thanks!

In the repository you can find a complete example of usage.

How to use it

Download

Use npm to download the library.

npm install ngx-bs-modals-creator

Then install and import bootstrap and jquery in angular.json as follows:

npm install bootstrap
npm install jquery

(bootstrap and jquery are not dependencies of the library in order to let you use the version you want, so you have to install them manually)

"styles": [
    "../node_modules/bootstrap/dist/css/bootstrap.min.css",
    ...
],
"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js",
    ...
],

Import the module

Import the module into the AppModule as follows:

src/app.module.ts

import { ModalsModule } from 'ngx-bs-modals-creator';

@NgModule({
	...
	imports: [ ...,  ModalsModule, ... ],
	...
})
export class AppModule { }

You have to import it just one time, if you try to import it in multiple modules, you will get an Exception.

Add the ModalsContainerComponent into the AppComponent template

Next you should import the ModalsContainerComponent into a template. This Component will create modals and will append them inside its template. As said before, Bootstrap modals works better if you put them near the body element, so it is suggested to add the selector as the last element in the AppComponent template.

src/app.component.html

<div>
	...my template...
</div>

<bdc-modals-container></bdc-modals-container>

Create a new modal

A modal is a Component, so you can create it in the same way. The only difference is that you have to extend BaseModalComponent<TArgument, TResult>. This is an example:

src/home/my-modal.component.ts

@Component({
	templateUrl: './my-modal.component.html'
})
export class MyModalComponent extends BaseModalComponent<void, string> {
	public constructor(elementRef: ElementRef) {
		super(elementRef);
	}
	
  public onModalInit(): void {
    console.log('Modal init');
  }

  public onModalViewReady(): void {
    console.log('Modal view ready');
  }

  public onModalDestroy(): void {
    console.log('Modal destroy');
  }

	// Use onModalInit() instead of ngOnInit() inside a modal. If you want to use it anyway, remember to call super.ngOnInit();. The same with ngOnDestroy
	// public ngOnInit(): void {
	//	 super.ngOnInit();
	// }
}

We are talking about Boostrap modals so the template has to follow the Bootstrap modal guide lines, but you can customize it as you like. This is an example: src/home/my-modal.component.ts

<div class="modal fade" id="{{id}}" tabindex="-1" role="dialog">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			...
			<div (click)="done()">Close me</div>
			...
		</div>
	</div>
</div>

Declare the modal

Now you have to register it in the module that contains it. This library allows you to use whatever module you want (lazy, eager, ...) but you need to register the modal in the declarations and in the entryComponents. This is an example:

src/home/home.module.ts

import { MyModalComponent } from './my-modal.component';

@NgModule({
	...,
	declarations: [
		...
		MyModalComponent
	],
	entryComponents: [MyModalComponent]
})
export class HomeModule { }

Open the modal

Everything is setup, so you just need to open the modal. To open it you need to use the ModalsService. ModalsService has just 2 methods: open and openAsync. The first accepts a callback as paramenter, the second returns a Promise. You can use them in the following way:

src/home/home.module.ts

import { MyModalComponent } from './my-modal.component';

class MyComponent {
	constructor(private d: ModalsService, private r: ComponentFactoryResolver) { }

	public openModal():void {
		this.d.show('my-modal-id', MyModalComponent, this.r, 'myArg', res => {
			console.log(res);
		});
	}

	public openModalAsync():void {
		this.d.showAsync('my-modal-id', MyModalComponent, this.r, 'myArg')
		.then(res => console.log(res)
		.catch(() => console.log('Modal closed by clicking on the shadow or pressing the "esc" button'));
	}
}

Contributors

  • Francesco Mazzarol
  • Gianluca Bonacin
  • Jonny Fox
  • Salvatore Di Stefano