Giter Club home page Giter Club logo

ngupgrade-lite-sample's Introduction

AngularJS 1.x + Angular (2+) Hybrid using ngUpgrade Lite

The boilerplate for using ngUpgrade Lite can be generated with Nx as an so called AngularJS Downgrade Module. For this, I've created a new Angular Project with the CLI using ng new ... and after switching to its folder I've used the following commands:

npm i @types/angular --save-dev
npm i @angular/upgrade --save
npm i @nrwl/schematics --save-dev

ng generate downgrade-module legacyApp --collection @nrwl/schematics 

Differences to NgUpgrade "classic"

This post shows how to use the AOT-aware NgUpgrade "classic".

Other than the "classic" version, the lite version does not automatically trigger the AngularJS 1.x change detection b/c it turned out that this can lead to hybrid apps with bad performance. Instead of this we have to trigger it by ourselves.

Also, we have to bootstrap AngularJS 1.x first and to reference the downgraded Angular (2+) main module. Moreover, When downgrading an Angular (2+) component we have to set propagateDigest to false:

const dgSubModule = angular
  .module('sub', [])
  .directive('appSub', downgradeComponent({ component: SubComponent, propagateDigest: false }))
  .factory('subService', downgradeInjectable(SubService));

const downgraded = angular
  .module('downgraded', [downgradeModule(bootstrapAngular), dgSubModule.name])
  .directive('appRoot', downgradeComponent({ component: AppComponent, propagateDigest: false }));

angular.bootstrap(document, ['phonecatApp', downgraded.name]);

More Infos can be found in the Nx documentation and in the current repo (e. g. see src/app/main.ts for bootstrapping or src/app/sub/sub.component.ts for triggering the $digest).

Experimental

This sample was created with Angular 5.x and at this time ngUpgrade Lite was marked as "experimental".

ngupgrade-lite-sample's People

Contributors

manfredsteyer avatar angular-cli avatar

Watchers

Ramin Mohammadi avatar James Cloos 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.