Giter Site home page Giter Site logo

angularjs-to-angular's Introduction

AngularJS to Angular Upgrade Path

Organization

angular-v1

Basic AngularJS application from https://github.com/angular/angular-seed

angular-v1-angular-v5

Hybrid application with tests for both AngularJS and Angular

Steps taken can be found in angular-v1-angular-v5/STEPS.md

src

Collection of scripts that have been useful for upgrading AngularJS to Angular.

Notes

AngularJS Components / Element Directives

  • must be changed to use closing tags

    from

     <app-component />
    

    to

     <app-component></app-component>
    

    this change was done to follow how web components must be formatted.

AngularJS Attribute Directives

  • currently ngUpgrade does not support upgrade or downgrade paths and must be rewritten.
  • ngAdapter extends ngUpgrade to support upgrade and downgrade paths for Angular 2. But does not work for Angular 4+ yet.

AngularJS Factory Provider for Angular

  // Class with code that does stuff
  class Foo {
    constructor(
      // dependencies
    ) {}
    ...
  }

  // AngularJS Factory
  export class FooFactory {
    public static $inject: string[] = [
      // dependencies as strings
    ];

    constructor(
      // dependencies
    ) {
      return new Foo(
        // dependencies
      )
    }
  }

  // Angular Service placeholder
  @Injectable()
  export class FooService extends Foo {}

  // function for Ahead of Time (AoT) compilation for Angular 5. Angular 6 can use () => {}
  export function fooService(injector: Injector) {
    return injector.get('fooFactory'); // name of the factory in AngularJS
  }

  // provider to replace Angular Service with the AngularJS Factory
  export const fooServiceProvider = {
    deps: ['$injector'],
    provide: FooService,
    useFactory: fooService,
  }

Usage in AngularJS

  import { FooFactory } from './fooFactory';

  export const ng1app = angular.module('ng1app', []).factory('fooFactory', FooFactory);

Usage in Angular

  import { fooServiceProvider } from './foo.service.provider';

  @NgModule({
    ...
    providers: [
      fooServiceProvider,
    ],
  })
  export class AppModule {}

Angular Service in AngularJS

  @Injectable()
  export class FooService { }

  // add to Angular
  @NgModule({
    providers: [
      FooService,
    ],
  })
  export class AppModule {}

  // add to AngularJS
  import { downgradeInjectable } from '@angular/upgrade/static';

  export const ng1app = angular.module('ng1app', []).factory(downgradeInjectable(FooService))

angularjs-to-angular's People

Contributors

vizjerai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.