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 🙏

© 2025 – Pkg Stats / Ryan Hefner

modal-lib2

v1.0.0

Published

Standalone Angular Modal System

Readme

modal-lib2

Lightweight, standalone Angular SSR-Safe modal system for Angular 17+. A service-based API to open any standalone component as a modal.

✨ Features

  • Angular 17+ standalone component support
  • Simple ModalService.open() API
  • Pass data into modal components via @Input()
  • Strongly typed result via ModalRef.afterClosed
  • Optional backdrop (opts.backdrop)
  • Programmatic close support
  • SSR-safe: queues on server, flushes on client

Installation

npm install modal-lib2

Quick Example

Modal Content Component

import { Component, inject, Input } from '@angular/core';
import { ModalRef } from 'modal-lib2';

export interface LoginResult {
  success: boolean;
  token?: string;
}

@Component({
  selector: 'app-login-modal',
  standalone: true,
  template: `
    <h3>Login</h3>
    <p>Hello, {{username}}</p>
    <button (click)="ok()">OK</button>
    <button (click)="cancel()">Cancel</button>
  `,
})
export class LoginModalComponent {
  @Input() username = '';
  private modalRef = inject<ModalRef<LoginResult>>(ModalRef);

  ok() {
    this.modalRef.close({ success: true, token: '123' });
  }

  cancel() {
    this.modalRef.close({ success: false });
  }
}

Open From Anywhere

import { Component, inject } from '@angular/core';
import { ModalService } from 'modal-lib2';
import { LoginModalComponent, LoginResult } from './login-modal.component';

@Component({
  selector: 'app-root',
  standalone: true,
  template: `<button (click)="open()">Open Login</button>`,
})
export class AppComponent {
  private modal = inject(ModalService);

  open() {
    const { ref, instance } = this.modal.open<LoginModalComponent, LoginResult>(
      LoginModalComponent,
      { username: 'Burt' },
      { backdrop: true }
    );

    ref.afterClosed.subscribe(result => {
      console.log('Closed with:', result);
    });

    console.log('Modal instance', instance);
  }
}

API

ModalService.open<T, TResult>(component, data?, opts?)

  • component – standalone component to render inside modal
  • data – partial object assigned to component’s @Input()s
  • opts – { backdrop?: boolean } (default: true)

Returns:

{
  ref: ModalRef<TResult>,
  instance: T | undefined,
  close: () => void
}

ModalRef

  • afterClosed: Observable<TResult | undefined>
  • close(result?: TResult): void

SSR NOTES

  • On the server, open() queues the request without touching the DOM.
  • On the client, it flushes once Angular is stable.
  • If you call close() on the server before hydration, nothing is rendered.

Changelog Highlights (1.0.0)

  • New API: ModalService.open<T, TResult>()
  • Strongly typed ModalRef.afterClosed
  • Removed host requirement (setModalHost)
  • Optional backdrop (opts.backdrop)
  • SSR-safe queuing