Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$Injector Error on Angular Upgrade from 1.6.6 to 6

I did Angular upgrade from Angular.Js 1.6.6 to Angular 6 using Webpack 4:


    import 'core-js/es7/reflect';
    import 'zone.js';
    import 'reflect-metadata';
    import 'rxjs';
    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { Routes, RouterModule } from '@angular/router';
    import { BrowserModule } from '@angular/platform-browser';
    import { UpgradeModule, downgradeComponent, downgradeInjectable, setAngularJSGlobal } from '@angular/upgrade/static';
    import { module } from './app.module.ajs';
    import './config/routes';
    import AppComponent from './components/app/app';
    import Application from './directives/application/application';
    import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
    console.log('NgModule');
    const appRoutes: Routes = [
    ];
    @NgModule({
      declarations: [AppComponent, Application],
      entryComponents: [AppComponent],
      imports: [
        BrowserModule,
        FormsModule,
        RouterModule.forRoot(appRoutes),
        UpgradeModule
      ]
    })
    class AppModule {
      constructor(public upgrade: UpgradeModule) {
        console.log('AppModule constructor');
      }
      ngDoBootstrap() {
        console.log('AppModule ngDoBootstrap');
      }
    }
    console.log('setAngularJSGlobal ...');
    setAngularJSGlobal(window['angular']);
    console.log('setAngularJSGlobal!!!');
    import main = require('./main');
    console.log('Before bootstrapModule module.name: ', module.name);
    platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
      console.log('Hybrid mode: Angular + Angular.Js');
      module.directive('appRoot', downgradeComponent({ component: AppComponent }));
      const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
      console.log('bootstrapModule: ', module.name);
      main['launchAngular']();
      upgrade.bootstrap(document.body, [module.name], { strictDi: true });
    });

created custom alias, added correct paths to tsconfig, Webpack build pass & produce output, but when application starts in browser, error popups in console: ngRoute is missing or incorrect ng module components What is not done correctly & how to fix this error?

like image 345
Droid Kree Avatar asked Aug 31 '18 15:08

Droid Kree


1 Answers

Fixed some Webpack aliases. Replaced: Angular-Resource with Axios, Angular-Route with UI-Router/Angular-Hybrid, refactored couple controllers to components/directives & services, got rid from $rootScope & Magic happened: Upgrade started to work.

like image 113
Droid Kree Avatar answered Nov 07 '22 17:11

Droid Kree