8

I have a app running AngularJS 1.5 and I'm trying to use NgUpgrade to start migrating old components to Angular.

My first step it's to have both frameworks running side by side. But when using NgUpgrade, I'm getting the following error:

Unhandled Promise rejection: [$injector:modulerr] Failed to instantiate module $$UpgradeModule due to:
Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module undefined due to:
Error: [ng:areq] Argument 'module' is not a function, got undefined

Basically I have an app.module.ts for Angular and app.js for AngularJS.

Following angular documentation, I created a main.ts to bootstrap both frameworks.

import { AppModule } from './app.module';

import { UpgradeModule } from '@angular/upgrade/static';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
    console.log('Bootstrap both Angular and AngularJS ');
    const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
    upgrade.bootstrap(document.body, ['myApp'], {strictDi: true});
});



For creating my bundle, I'm using webpack.
3
  • Did you find any resolutions for this error? Commented Nov 13, 2017 at 16:20
  • See post below. This is the current state of our AppModule. Working without a problem. Commented Nov 17, 2017 at 22:12
  • Did you find the solution of this? the module name was 'myApp' and now in bootstrap code you changed it to 'app'. This doesn't work for me. Commented Oct 18, 2022 at 12:26

1 Answer 1

1

This is the current state of our module. Most of the code is irrelevant to bootstrap both framework, since it's related with Redux. First, you need to remove the ng-app from the html and then inside of the constructor of the Module you need to call ngDoBootstrap() to bootstrap angular manually.

upgrade.bootstrap(document.body, ['app'], {strictDi: true}); will take care of bootstrapping your AngularJS application.

export class AppModule {
    constructor(private ngRedux: NgRedux<any>, @Inject(DIGEST_MIDDLEWARE) digestMiddleware: any) {
        const reducer = combineReducers({
            actions: actionsReducer,
            ...coreReducers
        });
        const initialStete = {
            actions: actionsInitialState,
            ...coreState
        };

        // digestMiddleware needs to be last, to support use in AngularJS 1.x
        const store = createStore(reducer, initialStete, applyMiddleware(thunk, logger, digestMiddleware) );
        ngRedux.provideStore(store);
    }
	ngDoBootstrap() {}
}


platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
	const upgrade = platformRef.injector.get(UpgradeModule);
	upgrade.bootstrap(document.body, ['app'], {strictDi: true});
});

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.