Angularで以下のようなコードを書き、
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
ng serveしてlocalhost:4200をブラウザで開き、検証ツールを開いたところ以下のようなエラーが出ました。
StaticInjectorError(AppModule)[RouterOutlet -> ChildrenOutletContexts]:
StaticInjectorError(Platform: core)[RouterOutlet -> ChildrenOutletContexts]:
NullInjectorError: No provider for ChildrenOutletContexts!
検索すると以下の記事が見つかりました。
1:Import the RouterModule (or any of the "versions" of it generated by forRoot or >forChildren methods) into the module that declares components that use the >directive.
2:The forRoot method of the RouterModule has to be called. Otherwise the services >required by the directive wont be initialized.
と記載してあったので、以下のように編集しました。
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule,
RouterModule,
RouterModule.forRoot([])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
エラー解消できました。