$Injector Error on Angular Upgrade from 1.6.6 to 6
Asked Answered
M

1

10

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?

Mercantile answered 31/8, 2018 at 15:23 Comment(0)
M
4

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.

Mercantile answered 5/9, 2018 at 10:4 Comment(2)
is there any documents to do that I am also facing that same issue please help me outImmunity
@Venkatsmart check this docs for example: angular.io/api/upgrade/static/downgradeModule angular.io/api/upgrade/static/UpgradeModule webpack.js.org/configuration/resolveMercantile

© 2022 - 2024 — McMap. All rights reserved.