园子博客后台升级至 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!
通过 Angular 17 Http client injection 的回答解决了
在 app.config.ts 中添加 provideHttpClient
export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(withFetch()),
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes)
]
};