我正在尝试在混合设置中并行运行 Angularjs 和 Angular17+。我遵循所有准则并创建了一个自定义 webpack 配置,以便能够打包我的 angularjs 文件和我的 Angular 文件。该应用程序似乎可以工作,但是当我尝试使用降级指南加载角度组件时,https://angular.io/guide/upgrade#using-angular-components-from-angularjs-code我得到了以下错误:
> angular.js:13708 NullInjectorError: R3InjectorError(Ng2AppModule)
[ComponentFactoryResolver$1 -> ComponentFactoryResolver$1]:
NullInjectorError: No provider for ComponentFactoryResolver$1!
at NullInjector.get (core.mjs:5605:1)
at R3Injector.get (core.mjs:6048:1)
at R3Injector.get (core.mjs:6048:1)
at NgAdapterInjector.get (static.mjs:1209:1)
at doDowngrade (static.mjs:771:1)
at static.mjs:798:1
at SyncPromise.then (static.mjs:633:1)
at Object.link (static.mjs:798:1)
at angular.js:1240:1
at invokeLinkFn (angular.js:9814:1)
似乎依赖注入无法正常工作?有什么想法如何解决这个问题吗?
要正常工作,请在
app.config.ts 中提供
*ComponentFactoryResolver*
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { provideClientHydration } from '@angular/platform-browser';
import { provideHttpClient } from '@angular/common/http';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes), provideClientHydration(), provideHttpClient() // import here]
};
关注提供商部分