首页 新闻 会员 周边 捐助

angular 19 中 HttpClient 的依赖注入问题

0
悬赏园豆:30 [已解决问题] 解决于 2025-01-03 07:20

园子博客后台升级至 angular 19 并改用 standalone bootstrapping api

import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';

bootstrapApplication(AppComponent, appConfig)
    .catch((err) => console.error(err));

运行时发现 HttpClient 没有被注册

NullInjectorError: R3InjectorError(Standalone[n])[t -> t -> e -> e]: 
  NullInjectorError: No provider for e!
dudu的主页 dudu | 高人七级 | 园豆:28541
提问于:2025-01-03 06:31
< >
分享
最佳答案
0

通过 Angular 17 Http client injection 的回答解决了

在 app.config.ts 中添加 provideHttpClient

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(withFetch()),
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideRouter(routes)
  ]
};
dudu | 高人七级 |园豆:28541 | 2025-01-03 07:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册