gpt4 book ai didi

angular - 没有简单组件的提供者

转载 作者:行者123 更新时间:2023-12-05 01:17:59 25 4
gpt4 key购买 nike

直到 5 分钟前它还在工作,这毫无意义......这是组件

import { Component, OnInit } from '@angular/core';
import {Osobaa} from '../osobaa';
import { Osoba } from '../osoba';
import {OsobaService} from '../osoba.service';

@Component({
selector: 'app-form-add',
templateUrl: './form-add.component.html',
styleUrls: ['./form-add.component.css']
})
export class FormAddComponent implements OnInit {
osoba : Osobaa;
constructor() { }

ngOnInit() { }

}

这是主要的 app.module.ts

import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import {FormsModule} from "@angular/forms";

import { AppComponent } from "./app.component";
import { HeaderComponent } from "./header/header.component";
import { LoginFormComponent } from "./login-form/login-form.component";
import { FooterComponent } from "./footer/footer.component";
import { DashboardComponent } from "./dashboard/dashboard.component";
import { RouterModule, Routes } from "@angular/router";
import {UserService} from './user.service';
import {AuthguardGuard} from './authguard.guard';
import { UserComponent } from "./user/user.component";
import { NotfoundComponent } from './notfound/notfound.component';
import { TableViewComponent } from './table-view/table-view.component';
import {HttpClientModule} from '@angular/common/http';
import {OsobaService} from './osoba.service';
import { HttpModule } from '@angular/http';
import { FormAddComponent } from './form-add/form-add.component';



const appRoutes: Routes = [
{
path: "",
component: LoginFormComponent
},
{
path: "add" ,
component: FormAddComponent
},
{
path: "table", component : TableViewComponent
},
{
path: "users/:name",
component : UserComponent
},
{
path: "dashboard",
canActivate:[AuthguardGuard],
component: DashboardComponent
},
{
path: '**',
component: NotfoundComponent
}
];

@NgModule({
declarations: [
AppComponent,
HeaderComponent,
LoginFormComponent,
FooterComponent,
DashboardComponent,
UserComponent,
NotfoundComponent,
TableViewComponent,
FormAddComponent
],
imports: [BrowserModule, RouterModule.forRoot(appRoutes),HttpModule,FormsModule],
providers: [UserService,AuthguardGuard,HttpClientModule,OsobaService],
bootstrap: [AppComponent]
})
export class AppModule {}

控制台错误是:

错误错误:未捕获( promise ):错误:StaticInjectorError [FormAddComponent]: 静态注入(inject)器错误[FormAddComponent]: NullInjectorError:没有 FormAddComponent 的提供者!错误:StaticInjectorError [FormAddComponent]: 静态注入(inject)器错误[FormAddComponent]: NullInjectorError: 没有 FormAddComponent 的提供者!

最佳答案

providers 中删除 HttpClientModule 模块,它应该放在 NgModuleimports 选项中。也可以尝试重新构建/重新运行应用程序。

可能您正在尝试将组件作为可注入(inject)的注入(inject)到服务中。

关于angular - 没有简单组件的提供者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47516090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com