• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 9 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fully featured .component() polyfill for Angular v1.3+

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

More Repositories

1

angularjs-styleguide

AngularJS styleguide for teams
5,965
star
2

echo

Lazy-loading images with data-* attributes
JavaScript
3,723
star
3

fireshell

Fiercely quick front-end boilerplate and workflows, HTML5, Grunt, Sass.
JavaScript
1,519
star
4

angular-1-5-components-app

A Contacts Manager application built on Angular 1.5 components, ui-router 1.0.0, Firebase.
JavaScript
573
star
5

flare

Unobtrusive event emitter API for Google Universal Analytics event tracking
JavaScript
505
star
6

angular-pizza-creator

Source code for Angular advanced Form APIs pizza builder
TypeScript
450
star
7

fluidvids

Fluid width (responsive) videos module, 1KB, custom players, dynamic elements/XHR support.
JavaScript
415
star
8

angular-dynamic-forms

Configurable Reactive Forms in Angular with dynamic components
TypeScript
317
star
9

angular-architecture

Angular architecture guide for teams.
262
star
10

apollo

Standalone cross-browser DOM class manipulation module
JavaScript
250
star
11

reactive-pizza

Angular v4.1.1 - Reactive Forms, Observables, Component Architecture. Pizza. 🍕
TypeScript
180
star
12

axis

Simple JavaScript type checking module. Returns a Boolean for each type check.
JavaScript
179
star
13

superbox

Superbox, the lightbox, reimagined
JavaScript
125
star
14

flaunt-js

Flaunt JS, stylish responsive navigations with nested click to reveal
CSS
89
star
15

linkjuice

Automatically wraps and creates anchor links for <h1-h6> headings
JavaScript
88
star
16

foreach

forEach implementation for Objects/NodeLists/Arrays, automatic type loops and context options
JavaScript
81
star
17

lunar

SVG class module for has/add/remove/toggleClass
JavaScript
78
star
18

stratos

Object manipulation module, simplified extends, keys, add/remove methods and more.
JavaScript
72
star
19

interpolate

Micro templating engine, maps Object property values to a String template
JavaScript
56
star
20

console.loge

Doge-driven debugging. Such console, many logs. Wow.
JavaScript
47
star
21

jbar

jBar, the lightweight jQuery notification banner.
CSS
32
star
22

superfast-angular-2

A super simple setup for Angular 2 to prototype or play around. Components, TypeScript and Routing.
JavaScript
32
star
23

gulp-oss

My Gulp.js boilerplate for creating new JavaScript projects
JavaScript
28
star
24

NoFi

No WiFi, detecting offline states with HTML5
JavaScript
25
star
25

switch-messages

switchMessages for Angular 1.2+, partial functionality from Angular 1.3+ "ngMessages"
JavaScript
24
star
26

fluidvids-react

React.js implementation of fluidvids.js
JavaScript
23
star
27

track-digests

A simple Directive to track $digest counts
JavaScript
21
star
28

psswrd

Show/hide toggling for password inputs.
JavaScript
21
star
29

ac-store

Simple Redux Store
TypeScript
19
star
30

angular-connect-2016

Final code for AngularConnect Angular 1 & 2 demos.
HTML
18
star
31

suave

Re-engineering the HTML5 <video> tag for semantics and modularity.
JavaScript
16
star
32

ac-boilerplate

TypeScript
15
star
33

mapify

Map iteration for Arrays and Objects
JavaScript
14
star
34

fluidvids-polymer

Web Component for fluidvids.js built with Polymer
14
star
35

ngrx-workshop

JavaScript
12
star
36

data-tabs

Simple HTML5 data-* jQuery tabs. Markup free and relative to their container for ultimate re-use.
12
star
37

workspaces-grunt

Using Grunt and Chrome Workspaces for in-browser development
JavaScript
10
star
38

fowa2014

FOWA 2014 workshop
CSS
7
star
39

ngWorkshop2015

[this is really old, wouldn't bother using it] Falsy Values AngularJS Workshop 2015
JavaScript
5
star
40

babel-private-properties-methods-classes

🔥 Babel + ESLint + Private Properties and Methods in Classes
5
star
41

imgShufflr

jQuery random image shufflr, inline img and background CSS
5
star
42

ngbe-2016

Source code moved here: https://github.com/toddmotto/angular-pizza-creator
5
star
43

selectnav

JavaScript select navigation for responsive projects
JavaScript
4
star
44

fitdevcomments

3
star
45

aot-loader

[BETA/Work In Progress] Ahead-of-Time Compiler for Webpack.
JavaScript
3
star
46

web-platform-angular-2

HTML
3
star
47

required-fallback

A robust HTML5 'required' attribute fallback, client-side jQuery script.
3
star
48

bounceThis

jQuery plugin that mimics CSS3 keyframes animations of bouncing headers
JavaScript
2
star
49

kendo-html-editor

HTML
2
star
50

fowd

CSS
1
star