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

ng2-router-modal

v0.0.8

Published

Angular2 module that integrates ng-bootstrap modal with ui-router state's tree

Downloads

14

Readme

npm version

NPM

ng2-router-modal

Angular2 module that integrates ng-bootstrap modal with ui-router state's tree.

DISCLAIMER! this module is still under high development; If you have suggestions and or problems feel free to post them on issues.

Features

  • State's tree integration: open modal with uiSref; unique URL for page with modal opened; auto close modal backtrack.
  • Async callback: register callback for onClose/onDismiss at parent state controller.
  • Open modal with params: open modal without State Tree / Url integration ; access parameters inside the modal the same way;

Install

npm install ng2-router-modal

and add to AppModule and initialize modal states initialization at UIRouter config function,

@NgModule({
  imports: [
    ... 
    UIRouterModule.forRoot({
        ...
        config: function(router: UIRouter, injector: Injector){
            let rmService = injector.get(RmService);
            let states = injector.get(StateService).get();
            rmService.initModalStates(states);
            ...
        }
    }),
    ResourceModule.forRoot()
  ],
})

How to use

Creating a simple Modal

Start by creating a service that extends RmService. Declare the modal params with @ModalParams and action specific params with @ModalAction annotations.

import {RmModal, ModalParams, ModalAction} from "ng2-router-modal";
import {ThingModalComponent} from "./thing-modal.component";

import {NgbModalRef} from "@ng-bootstrap/ng-bootstrap";

@Injectable()
@ModalParams({
    name: 'thing',
    component: ThingModalComponent
})
export class ThingModal extends RmModal {

    @ModalAction({})
    create: NgbModalRef;
    
    @ModalAction({
        urlParams: '{id:int}'
    })
    update: NgbModalRef;
    
}

./thing-modal.component.ts is your regular component containing the ng-bootstrap Modal:

@Component({
    selector: 'thing-modal',
    templateUrl: 'thing-modal.html',
    ... 
})
export class ThingModalComponent implements OnInit{

    constructor(private activeModal: NgbActiveModal, private rmService: RmService, ...) {
    }
    
    ngOnInit(){
        console.log(rmService.params.id); 
    }
    ... 
}

add/link the modal to an existing state (./some-module.states.ts):

name: 'somePage',
url: '/somepage',
component: SomepageComponent,
data: {
    ...
    modals: [
        ThingModal
    ]
}
...

Open your modal at your-website/somepage/create-thing to create a new Thing or your-website/somepage/update-thing/123 to update an existing Thing. You can update the modal pragmatically via the state names (do not forget to pass the parameters).

<a uiSref='somePage.createThing'>New Thing</a>
<a uiSref='somePage.updateThing' [uiParams]='{id: 123}'>Update Thing 123</a>

Subscribing for onClose/onDismiss callback

The handler is called every time the modal/action is closed/dismissed. do not forget to unsubscribe the observers

export class SomepageComponent implements OnDestroy {

    constructor(private rmService: RmService ... ){
        this.thingCloseSub = rmService.onClose(['createThing', 'updateThing']).subscribe((thing: any) => {
               console.log(thing)
        });
        
        this.thingDismissSub = rmService.onDismiss(['createThing']).subscribe((thing: any) => {
           console.log('user dismissed modal when creating a thing');
        });
        ...        
    }
    
    ngOnDestroy(): void {
        this.thingCloseSub.unsubscribe();
        this.thingDismissSub.unsubscribe();
    }
}
...

Open modal with params

Using the open method you can use the returned promise or the onClose/onDismiss methods to receive the result.

export class NavbarComponent {

    constructor(private rmService: RmService ... ){}
    
    openThing(): void {
        this.rmService.open(ThingModal, 'create', {someparam: 'some value'}).then(
                thing => (console.log(thing),
                msg => console.log('user dismissed modal with ' + msg )
        );
    }
}
...

(in progress)