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

@rahmaniali.ir/angular-modal

v0.0.4

Published

Easily open your own customized modals! angular-modal let's you easily open your own components as modals, you can pass inputs and options and get results and customize the look and feel pretty easily!

Downloads

87

Readme

Angular Modal

Easily open your own customized modals!
angular-modal let's you easily open your own components as modals, you can pass inputs and options and get results and customize the look and feel pretty easily!

Installation

To install from npm simply run:

npm i @rahmaniali.ir/angular-modal

How to use

To open a component, first inject the modal service in you service or component:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.sass']
})
export class AppComponent {
  constructor(private modalService: ModalService) {}
}

Then, import your component and use the open method on the service and pass the component:

import { ExampleModalComponent } from './example-modal/example-modal.component';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.sass']
})
export class AppComponent {
  constructor(private modalService: ModalService) {}

  openModal() {
    this.modalService.open(ExampleModalComponent)
  }
}

That's it! That's the simplest way you can use angular-modal. If you need to pass options to your component, or get results from it, follow along.

Options

When you are opening a component, you may need to pass some extra information about the modal.
These options are: input, persistent and customClass.

input

Consider you have a component that accepts input. You can pass these inputs when you are opening a modal by passing the options object:

this.modalService.open(ExampleModalComponent, {
  input: {
    name: 'Jon',
    age: 23
  }
})

Here, we are passing name and age as inputs to the ExampleModalComponent.

persistent

By default, clicking outside the modal, will dismiss it. To prevent this behaviour you can pass persistent:true as an option when opening a modal:

this.modalService.open(ExampleModalComponent, {
  persistent: true
})

customClass

You can assign a class to the modal wrapper in case you want to style it:

this.modalService.open(ExampleModalComponent, {
  customClass: 'red-alert'
})

This will apply the red-alert class to the modal-wrapper which is the wrapper for your component and basically is responsible for the background.
Now, you can define your custom style like this:

modal-wrapper.red-alert {
  background: red;
}

Yeah, I know, pretty hard to look at... but it's just an example; Take it easy!

Output results

Now let's say you have your modal, and you want to pass some data to the component/service that opened it. You need to import and inject the ActiveModal service in your component. Take a look:

import { ActiveModal } from '@rahmaniali.ir/angular-modal'

@Component({
  selector: 'app-example-modal',
  templateUrl: './example-modal.component.html',
  styleUrls: ['./example-modal.component.sass']
})
export class ExampleModalComponent {
  constructor(activeModal: ActiveModal) {}
}

Now you have a reference to the modal inside itself. Cool.
By having the reference you can close or dismiss the modal, or update its options.
For example, let's say I need my modal to send 'some string' back to the component that opened it:

@Component({
  selector: 'app-example-modal',
  templateUrl: './example-modal.component.html',
  styleUrls: ['./example-modal.component.sass']
})
export class ExampleModalComponent {
  constructor(private activeModal: ActiveModal) {}

  close() {
    this.activeModal.close('some string')
  }
}

Now, how to get this 'some string' value in the parent component? For this you'll have to subscribe to the result of the open method like this:

openModal() {
  const modalRef = this.modalService.open(ExampleModalComponent, {
    customClass: 'red-alert',
  });

  modalRef.result.subscribe({
    next: (data) => {
      // data = 'some string'
    },
    error: (data) => {}
  })
}

The open method returns a ModalRef object. By using it, you can close or dismiss, subscribe to the result or update the options from the parent as well.

No need to say that if you dismiss the modal, tha parent subscriber will run the error function.

Support me

This is the earliest version that I'm sharing, more features and fixes are yet to come to make it even easier and more enjoyable to use. Please consider giving star the repo on Github if you liked angular-modal or if you didn't I'd love to know why? So please open an issue to let me know!

Thanks,
A.