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

@sungazer/angular-route-decorators

v2.0.0

Published

This library offers 3 property decorators for common route operations. These decorators allow to automatically get snapshots or observables for values taken from the component's ActivatedRoute `paramMap`, `queryParamMap` and `data` properties.

Downloads

4

Readme

AngularRouteDecorators

This library offers 3 property decorators for common route operations. These decorators allow to automatically get snapshots or observables for values taken from the component's ActivatedRoute paramMap, queryParamMap and data properties.

How to use

Import AngularRouteDecoratorsModule in your root AppModule.

Make sure that your component extends from the provided mixin class:

import {Component} from '@angular/core';
import {WithRouteDecorators} from '@sungazer/angular-route-decorators';

export class InnerPageComponent extends WithRouteDecorators() {

}

If your component is already extending a base component, just place the base component between the round brackets of the mixin.

import {Component} from '@angular/core';
import {WithRouteDecorators} from '@sungazer/angular-route-decorators';

export class InnerPageComponent extends WithRouteDecorators(BaseComponent) {

}

The mixin provides a base implementation for ngOnInit and ngOnDestroy, if your component uses any of these two hooks, please remember to call the parent method:

import {Component, OnDestroy, OnInit} from '@angular/core';
import {WithRouteDecorators} from '@sungazer/angular-route-decorators';

export class InnerPageComponent extends WithRouteDecorators() implements OnInit, OnDestroy {

  ngOnInit(){
    super.ngOnInit();
  }

  ngOnDestroy(){
    super.ngOnDestroy();
  }
}

Finally, decorate your properties


import {Component, OnDestroy, OnInit} from '@angular/core';
import {Location} from '@angular/common';
import {RouteParam, WithRouteDecorators, RouteQueryParam, RouteData} from '@sungazer/angular-route-decorators';
import {Observable} from 'rxjs';

@Component({
  selector: 'app-inner-page',
  templateUrl: './inner-page.component.html',
  styleUrls: ['./inner-page.component.scss']
})
export class SampleComponent extends WithRouteDecorators() implements OnInit {

    // Contains the snapshot value for the path parameter 'param'
    @RouteParam() param: string;
    // Contains an observable that fires for any change of the path parameter 'param'
    @RouteParam({observable: true}) param$: Observable<string>;
    // Contains the snapshot value for the path parameter 'param'
    @RouteParam({paramName: 'param'}) param2: string;
    // Contains an observable that fires for any change of the path parameter 'param'
    @RouteParam({paramName: 'param', observable: true}) param2$: Observable<string>;
  
    // Contains the snapshot value for the query parameter 'query'
    @RouteQueryParam() query: string;
    // Contains an observable that fires for any change of the query parameter 'query'
    @RouteQueryParam({observable: true}) query$: Observable<string>;
    // (You can specify paramName here as well)
  
    // Contains the snapshot value for the data parameter 'dataKey'
    @RouteData() dataKey: string;
    // Contains an observable that fires for any change of the data parameter 'dataKey'
    @RouteData({observable: true}) dataKey$: Observable<string>;
    // (You can specify paramName here as well)
  
    // Same as above, the RouteData decorator also works for objects set in the data portion of the route
    @RouteData() dataKeyObject: any;
    @RouteData({observable: true}) dataKeyObject$: Observable<any>;

  constructor() {
    super();
  }

  ngOnInit(): void {
    super.ngOnInit();
  }
}

Why the mixin class

According to https://github.com/angular/angular/issues/31495, it is not possible to runtime-patch functions such as ngOnInit etc. For the time being (waiting for Component Features ) the mixin helps in processing the decorator's metadata.