Sharing Top Content from the Angular-sphere.

Writing AngularJS (>=1.5) component using Angular (>=2) approach with TypeScript… · GitHub

An experiment to use #Angular's @Component in #AngularJs app

  • Instantly share code, notes, and snippets.
  • Sign up for a GitHub account Sign in
  • We recommend upgrading to the latest Internet Explorer , Google Chrome , or Firefox .
  • IHttpService ) {} $onInit() { // do something with this.bar or this.$http upon initialization } }
  • Sign up for free to join this conversation on GitHub .


@manekinekko: An experiment to use #Angular’s @Component in #AngularJs app

We recommend upgrading to the latest Safari, Google Chrome, or Firefox.

If you want to write an AngularJs (1.5) component using Angular (>=2) approach, you could use:

import { FooComponent } from ‘./foo.component’; angular.module(‘app.module’, []) .component(‘fooComponent’, FooComponent);

import { Component } from ‘./core/helpers/decorators’; @Component({ bindings: { bar: ‘<' }, template: '

{{$ctrl.bar}}

‘ }) export class FooComponent { bar: string; constructor(public $http : ng.IHttpService) {} $onInit() { // do something with this.bar or this.$http upon initialization } }

export const Component = function(options : ng.IComponentOptions): Function { return (controller : Function) => { return angular.extend(options, { controller }); }; };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Writing AngularJS (>=1.5) component using Angular (>=2) approach with TypeScript… · GitHub

Comments are closed, but trackbacks and pingbacks are open.