错误信息:
错误 NullInjectorError: R3InjectorError(AppModule)[AlertPanelComponent -> AlertPanelComponent -> AlertPanelComponent]: NullInjectorError: No provider for AlertPanelComponent!角
我不明白这一点,我只是想AlertPanelComponent
从 alert-panel.component 导入我的。
在 stackOverflow 上搜索时,此错误似乎非常广泛。我已经把它放在了我的 app.module 中。
app.component.ts
import {AlertClass} from './models/alert-class.model';
...
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, DoCheck {
...
constructor( private restService:RestService,
private sanitizer: DomSanitizer,
private router:Router,
private alertPanelComponent:AlertPanelComponent ){
}
...
}
app.module.ts
import { AlertPanelComponent } from './alert-panel/alert-panel.component';
...
@NgModule({
declarations: [
AlertPanelComponent,
...
],
...
})
export class AppModule { }
应用程序路由.module.ts
import { NgModule } from '@angular/core';
import { RouterModule,
Routes,
PreloadAllModules} from '@angular/router';
import {LoginComponent} from './login/login.component';
import {AlertPanelComponent} from './alert-panel/alert-panel.component';
import {WebCamComponent} from './web-cam/web-cam.component';
const routes: Routes = [
{path: '',component: LoginComponent},
{path: 'alert-panel',component: AlertPanelComponent},
{path: 'webcam', component: WebCamComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes)
],
exports: [RouterModule]
})
export class AppRoutingModule { }