1

I've managed to successfully bootstrap my hybrid app, but as soon as I try to use a downgraded Angular component directive in my AngularJS template I'm getting this error:

Error: StaticInjectorError[{providers:[[object Object]], parent:[object Object], name:"DowngradeComponentAdapter"}]: Unexpected provider
    at staticError (core.js:1360)
    at recursivelyProcessProviders (core.js:1209)
    at new StaticInjector (core.js:1079)
    at Function.webpackJsonp../node_modules/@angular/core/esm5/core.js.Injector.create (core.js:1051)
    at DowngradeComponentAdapter.webpackJsonp../node_modules/@angular/upgrade/esm5/static.js.DowngradeComponentAdapter.createComponent (static.js:230)
    at doDowngrade (static.js:528)
    at Object.link (static.js:554)
    at angular.js:1383
    at invokeLinkFn (angular.js:10610)
    at nodeLinkFn (angular.js:9999) "<test-comp>"

Both my AngularJS host component and are very simple static components. Can't google anything similar. Please help.

3 Answers 3

2

The issue apparently was that I've had a more recent version of @angular/upgrade installed (5.2) and it wasn't compatible with other angular packages on my system (5.1).

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

1 Comment

I appreciate your answer. I was also facing same issue. I think all the angular packages should have same version otherwise things will go south
1

If I understood your problem correctly, you are trying to use an Angular component from AngularJS code. Given this is correct, hopefully the below information should help:

  1. The resulting downgraded component which is a directive, you need to register that in the AngularJS module.

    angular.module('yourApp', [])
           .directive(
           'yourComponent',
           downgradeComponent({ component: YourComponent }) as 
           angular.IDirectiveFactory);
    
  2. Because this is an Angular component, you need to add it to your AppModule declarations.
  3. As this component is being used by AngularJS module and if it is an entry point, add it to entryComponents for NgModule.

I am guessing you missed to register the component somewhere. For reference - https://angular.io/guide/upgrade#using-angular-components-from-angularjs-code for more information

Comments

0

Try to import the HttpClientModule in your app.module.ts

import { HttpClientModule } from '@angular/common/http';

@NgModule({
    imports: [
     HttpClientModule
    ]
}) 

1 Comment

What would the solution look like, when my angular.module code is written in JavaScript and not TypeScript? I have been looking for a sample project which demonstrates how to downgrade an Angular component to be used in an AngularJS application which is written in pure JavaScript. However, everything I find are AngularJS apps that are written in TypeScript.

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.