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

ng-hybrid-decorators

v1.1.0

Published

A few decorators to ease maintenance/evolution of angularjs/Angular hybrid applications

Downloads

12

Readme

ng-hybrid-decorators

GitHub Workflow Status npm npm bundle size StackBlitz

Some Typescript decorators to ease maintenance/evolution of angularjs/Angular(>5) hybrid applications by removing a lot of boilerplate code:

  • @ng1Service(): Makes an Angular service injectable in angularjs services/components

  • @ng1Inject(): Injects an angularjs service in Angular sevice/component

  • @ng1Component(): Makes an Angular component usable in angularjs templates

This micro library (5kb) is based on official recommendation.

Compatible with AOT and Ivy, tested with Angular 6/7/9/10 (although it might work with others)

See some examples below or the online demo or fork it on stackblitz

@ng1Service()

Angular service downgraded to angularjs:

@Injectable()
@ng1Service('NewCatService')
export class NewCatService {

  getNewSound(): string {
    return "Meow meow meow";
  }

}

angularjs controller/service can now inject it:

angular
  .module('demo.app')
  .factory('CatService', CatService);

function CatService(NewCatService) {

  var service = {
    getSound: getSound,
  }

  return service;

  function getSound() {
    return NewCatService.getNewSound();
  }

}

@ng1Inject()

Considering an angularjs service:

angular
  .module('demo.app')
  .factory('OldElephantService', function() {

    var service = {
      getSound: getSound,
    }

    return service;

    function getSound() {
      return 'Pwoa pwoa pwoaaa';
    }
  
});

It is easily injected in Angular services/components:

@Injectable()
export class ElephantService {

  @ng1Inject() oldElephantService: any;

  getSound(): string {
    return this.oldElephantService.getSound();
  }

}

@ng1Component()

Angular component downgraded to angularjs:

@ng1Component('newGiraffe')
@Component({
  selector: 'new-giraffe',
  templateUrl: './new-giraffe.component.html',
})
export class NewGiraffeComponent {

  @Input() sound!: string;
}

Angular component can then be used in angularjs template:

angular
    .module('demo.app')
    .directive('giraffe', giraffe);

  function giraffe() {
    var directive = {
      restrict: 'E',
      template: `<new-giraffe [sound]="'Bleat bleat bleat'"></new-giraffe>`,
      controller: 'GiraffeController',
      controllerAs: 'GiraffeCtrl',
    };
    return directive;
  }

See also the online demo or fork it on stackblitz

Installation

npm i ng-hybrid-decorators

Setup

NgHybridService needs to be called where the hybrid app is configured:

export class AppModule {

  constructor(private upgradeModule: UpgradeModule, private ngHybridService: NgHybridService) {
  }

  // noinspection JSUnusedGlobalSymbols
  public ngDoBootstrap(): void {
    const angularJsModule = angular.module('demo.app', []);

    this.ngHybridService.loadNg1Dependencies(angularJsModule);

    this.upgradeModule.bootstrap(document.body, ['demo.app'], {strictDi: true});
  }

}

See demo source code

Run demo locally

git clone https://github.com/domi7777/ng-hybrid-decorators.git
cd ng-hybrid-decorators
npm i
npm run update-demo
npm run demo