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

angular-component

v0.1.3

Published

Angular component() polyfill

Downloads

5,054

Readme

angular-component.js

Start using .component() now!

View live demo in v1.3.0

angular-component.js is a ~1kb script that adds component() support in Angular 1.5 to all Angular versions above 1.3, so you can begin using the new method now.

Note: you must include this script straight after angular.js and before your application code to ensure the component() method has been added to the angular.module global.

Read about the Angular 1.5 component() method here

Polyfill support

This polyfill supports the following feature set of the .component() method:

| Feature | Supports | |----------------------------------------------------------------|-----------| | angular.module.component() method | Yes | | bindings property | Yes | | 'E' restrict default | Yes | | $ctrl controllerAs default | Yes | | transclude property | Yes | | template support | Yes | | templateUrl injectable for $element and $attrs | Yes | | One-way data-binding emulated | Yes | | Lifecycles: $onInit, $onChangesm $postLink, $onDestroy | Yes | | require Object for parent Component inheritance | Yes | | $ prefixed properties such as $canActivate | Yes |

Component method usage

<div ng-app="app">
  <div ng-controller="MainCtrl as vm">
    <counter count="vm.count"></counter>
  </div>
</div>

<script>
angular
	.module('app', [])
  .component('parentComponent', {
    template: `
      <div>
        {{ $ctrl.user }}
        <child-component user="$ctrl.user" on-update="$ctrl.updateUser($event);"></child-component>
      </div>
    `,
    controller: function () {
      this.user = {
        name: 'Todd',
        location: 'England, UK'
      };
      this.updateUser = function (event) {
        this.user = event.user;
      };
    }
  })
	.component('childComponent', {
    bindings: {
      user: '<',
      onUpdate: '&'
    },
    controller: function () {
    	this.$onInit = function () {
        // component initialisation
      };
      this.$onChanges = function (changes) {
        if (changes.user) {
          this.user = angular.copy(this.user);
        }
      };
      this.$postLink = function () {
        // component post-link
      };
      this.$onDestroy = function () {
        // component $destroy function
      };
    },
    template: `
      <div>
        <input type="text" ng-model="$ctrl.user.name">
        <a href="" ng-click="$ctrl.onUpdate({$event: {user: $ctrl.user}});">Update</a>
      </div>
    `
  });
</script>

Installing with NPM

npm install angular-component --save

Installing with Bower

bower install angular-component.js --save

Manual installation

Ensure you're using the files from the dist directory (contains compiled production-ready code). Ensure you place the script before the closing </body> tag.

<body>
  <!-- html above -->
  <script src="angular-1.x.js"></script>
  <script src="dist/angular-component.js"></script>
  <script src="app.js"></script>
</body>

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Gulp.

Release history

  • 0.1.2
    • Version fixes
  • 0.1.1
    • Version fixes
  • 0.1.0
    • Add one-way data-binding and $onChanges lifecycle, stable release
  • 0.0.8
    • Add new lifecycle hooks ($onInit, $onDestroy, $postLink)
  • 0.0.7
    • Add require property from 1.5 stable, restrict: 'E' as default
  • 0.0.6
    • Add automated $ prefixed properties to factory Object
  • 0.0.5
    • Add automatic function annotations
  • 0.0.4
    • Fix Array dependency annotations #11
  • 0.0.3
    • Fix bug caused by bugfix (aligns with new 1.5 changes)
  • 0.0.2
    • Bugfix isolate scope when bindings is omitted, short-circuit if .component() is already supported
  • 0.0.1
    • Initial release