I am trying to download an Angular 1.X application from Angular 2+ (Angular 4.1.0 at the time of this writing). I followed the online guide to T, but it seems that it can not move forward.
I am using a hybrid of ES2015 + (compiled via Babel) and TypeScript. Everything compiles correctly, and I can successfully run both Angular 1 and Angular 2. They compile together using Webpack, if that matters.
This is what my Angular 1.X file ( app.ts ) looks like:
import * as angular from 'angular'; export default angular.module('app', []) .run(function() { console.log('Angular 1 is running!')})
For simplicity, I removed all the dependencies from the main application so that I can make sure that this is not a run / config function or one of the dependencies. I tested with the config / run functions to see if any of these start or throw errors exist, but they do not.
Then I have an input file for my Angular 2+ application (which I also use as the input file for Webpack) called main.ts , which looks like this:
import 'core-js/es7/reflect'; import 'zone.js'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { UpgradeModule } from '@angular/upgrade/static'; import { AppModule } from './app.module'; import app from '../app/app'; const platform = platformBrowserDynamic(); platform.bootstrapModule(AppModule).then(platformRef => { console.log('angular 2+ bootstrapped'); const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule; console.log('getting update module'); console.log('app', app) upgrade.bootstrap(document.body, [app.name], { strictDi: true}) console.log('should be bootstrapped') })
The process crashes after the line console.log('app', app) . The magazine shows that the app indeed an instance of the Angular 1.X application. But the bootstrap process is still not working.
Any ideas on what I'm not doing right?
EDIT
Here is my app.module file:
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { UpgradeModule } from '@angular/upgrade/static'; import { AppComponent } from './app.component'; @NgModule({ imports: [ BrowserModule, UpgradeModule ], declarations: [ AppComponent ], entryComponents: [ AppComponent ] }) export class AppModule { constructor(protected upgrade: UpgradeModule) {} ngDoBootstrap() { } };
EDIT2
My guess is that Angular 2+ depends on the fact that AngularJS 1.X is already on the window object. I am running AngularJS 1.X from inside the module. I will update when I work on it. I answered a few comments below. I am currently using the simplest example possible, and for AngularJS 1.X, I literally run a bubbly application that logs out if it is loaded via .run
EDIT 3
I posted the answer below. It main.ts import ordering in the main.ts file (recording file). Just importing the AngularJS 1.X application before importing zone.js fixed the problem.