我遇到一些奇怪的错误:-
错误:无法解析AdminProductsComponent的所有参数:(?,?,[对象对象],[对象对象])。
我找不到错误,并且该错误仅针对此组件显示,而对于其他组件则不在同一组件中显示。 请帮忙!
admin-products.component.ts
import { Component, OnInit } from '@angular/core';
import { ItemsService } from 'src/app/services/items.service';
import { ProductsService } from 'src/app/services/products.service';
import { Router, ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-admin-products',
templateUrl: './admin-products.component.html',
styleUrls: ['./admin-products.component.scss']
})
export class AdminProductsComponent implements OnInit {
subscription: Subscription
subscription1: Subscription
constructor(
public iservice: ItemsService,
private prservice: ProductsService,
private router: Router,
private route: ActivatedRoute
) {}
ngOnInit() {
this.iservice.getdata().subscribe(data => {
this.alldata = data
});
}
onclick(el) {
this.prservice.editchanged.next(el)
this.router.navigate(['admin/products/edit'])
}
}
app.module.ts
import { UserResolver } from './home/home.resolver';
import { AuthGuard } from './home/auth-guard';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { AngularFireModule } from 'angularfire2';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { environment } from '../environments/environment';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { AppRouting } from './app.routes';
import { UserService } from './auth/user.service';
import { AuthService } from './auth/auth.service';
import { ItemsService } from './services/items.service';
import { AdminOrdersComponent } from './admin/admin-orders/admin-orders.component';
import { AdminProductsComponent } from './admin/admin-products/admin-products.component';
import { ProductsService } from './services/products.service';
import { HttpModule } from '@angular/http';
import { AdminEditComponent } from './admin/admin-edit/admin-edit.component';
@NgModule({
declarations: [
AppComponent,
AdminOrdersComponent,
AdminProductsComponent,
AdminEditComponent,
],
imports: [
AngularFireModule.initializeApp(environment.firebase),
AngularFirestoreModule, // imports firebase/firestore, only needed for database features
AngularFireAuthModule, // imports firebase/auth, only needed for auth features
BrowserModule,
FormsModule,
ReactiveFormsModule,
AppRouting,
MDBBootstrapModule.forRoot(),
HttpModule,
],
providers:[
AuthGuard,
UserService,
AuthService,
UserResolver,
ItemsService,
ProductsService
],
bootstrap: [AppComponent]
})
export class AppModule {}
app.routes.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { UserResolver } from './home/home.resolver';
import { AuthGuard } from './home/auth-guard';
import { AdminProductsComponent } from "./admin/admin-products/admin-products.component";
import { AdminOrdersComponent } from "./admin/admin-orders/admin-orders.component";
import { AdminEditComponent } from "./admin/admin-edit/admin-edit.component";
const rootRouterConfig: Routes = [
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent, canActivate: [AuthGuard] },
{ path: 'register', component: RegisterComponent, canActivate: [AuthGuard] },
{ path: 'home', component: HomeComponent, resolve: { data: UserResolver } },
{ path: 'admin/products', component: AdminProductsComponent },
{ path: 'admin/products/edit', component: AdminEditComponent },
{ path: 'admin/orders', component: AdminOrdersComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(rootRouterConfig)
],
exports: [RouterModule]
})
export class AppRouting { }
答案 0 :(得分:1)
在您的AdminProductsComponent构造函数中,
constructor(
public iservice: ItemsService,
private prservice: ProductsService,
private router: Router,
private route: ActivatedRoute
) {}
您插入了两个服务,称为ItemsService和ProductsService。在大多数情况下,您可能忘记为这两项服务添加“ @Injectable()”注释。