ng build --prod给了我一个错误

时间:2017-11-30 23:30:18

标签: javascript angular typescript angular-cli

添加了 app模块,只有一个DataService声明

这是我尝试构建生产应用时遇到的错误。我检查了所有进口,参数是对的,一切似乎都没问题。也许我错过了什么。所有服务也都是进口的。

ERROR in Error: Can't resolve all parameters for DataService in /Users/avide/WebstormProjects/cocina/cocina.do/src/app/services/data.service.ts: (?, [object Object]).

这是DataService文件



import {AppError} from '../common/app-error';
import {NotFoundError} from '../common/not-found-error';
import {BadInput} from '../common/bad-input';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Http} from '@angular/http';

@Injectable()
export class DataService {
  constructor(private url: string, private http: Http) {
  }

........

}
  




这是app.module



import { UserService } from './services/user.service';
import { FavoriteService } from './services/favorite.service';
import { LikeService } from './services/like.service';
import { PostService } from './services/post.service';
import { SocialService } from './services/social.service';
import { EmailService } from './services/email.service';
import { DataService } from './services/data.service';
import { RecipeService } from './services/recipe.service';
import { AuthService } from './services/auth.service';
import { NotFoundComponent } from './not-found/not-found.component';
import { NoAccessComponent } from './no-access/no-access.component';

import { RecipeFormComponent } from './admin/recipe-form/recipe-form.component';
import { AdminComponent } from './admin/admin/admin.component';
import { RouterModule } from '@angular/router';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NavbarComponent } from './navbar/navbar.component';
import { HomeComponent } from './home/home.component';
import { EmailFormComponent } from './email-form/email-form.component';
import { RecipeComponent } from './recipe/recipe.component';
import { SearchComponent } from './search/search.component';
import { CategoriesComponent } from './categories/categories.component';
import { LoginFormComponent } from './login-form/login-form.component';
import { SigninFormComponent } from './signin-form/signin-form.component';
import { FilterPipe } from './filter.pipe';
import { CapitalizePipe } from './capitalize.pipe';
import {NgxPaginationModule} from 'ngx-pagination';
import { PostFormComponent } from './admin/post-form/post-form.component';
import { AboutComponent } from './about/about.component';
import { AlertComponent } from './alert/alert.component';
import { LikeComponent } from './like/like.component';
import { FavoriteComponent } from './favorite/favorite.component';
import { ProfileComponent } from './profile/profile.component';
import { BlogComponent } from './blog/blog.component';
import { PostComponent } from './post/post.component';
import {AuthGuard} from './auth.guard';
import {AdminAuthGuard} from './admin-auth.guard';

@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent,
    HomeComponent,
    EmailFormComponent,
    RecipeComponent,
    SearchComponent,
    CategoriesComponent,
    RecipeFormComponent,
    LoginFormComponent,
    SigninFormComponent,
    AdminComponent,
    FilterPipe,
    CapitalizePipe,
    PostFormComponent,
    AboutComponent,
    AlertComponent,
    NoAccessComponent,
    NotFoundComponent,
    LikeComponent,
    FavoriteComponent,
    ProfileComponent,
    BlogComponent,
    PostComponent
  ],
  imports: [
    BrowserModule,
    HttpModule,
    FormsModule,
    ReactiveFormsModule,
    NgxPaginationModule,
    RouterModule.forRoot([
      { path: '', component: HomeComponent},
      { path: 'receta/:categoria/:pais/:id', component: RecipeComponent },
      { path: 'blog/:id', component: PostComponent },
      { path: 'about', component: AboutComponent},
      { path: 'search', component: SearchComponent},
      { path: 'blog', component: BlogComponent },
      { path: 'post', component: BlogComponent },
      { path: 'perfil/:username', component: ProfileComponent, canActivate: [AuthGuard] },
      { path: 'admin/post/new', component: PostFormComponent, canActivate: [AuthGuard, AdminAuthGuard] },
      { path: 'admin/receta/new', component: RecipeFormComponent, canActivate: [AuthGuard, AdminAuthGuard] },
      { path: 'admin/receta/edit/:id', component: RecipeFormComponent, canActivate: [AuthGuard, AdminAuthGuard] },
      { path: 'admin', component: AdminComponent, canActivate: [AuthGuard, AdminAuthGuard] },
      { path: 'login', component: LoginFormComponent },
      { path: 'register', component: SigninFormComponent },
      { path: 'unauthorized', component: NoAccessComponent },
      { path: '**', component: NotFoundComponent }
    ])
  ],
  providers: [
    DataService,
    RecipeService,
    EmailService,
    SocialService,
    PostService,
    AuthService,
    LikeService,
    FavoriteService,
    UserService,
    AuthGuard,
    AdminAuthGuard
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }




1 个答案:

答案 0 :(得分:1)

这对我有用。 https://stackoverflow.com/a/35041823/8585804

@Injectable()
export class ParentService {
  root:string = "This content comes from: ";
  myString:string = "The Parent";
  resultString:string;
  constructor(){
    this.init();
  }
  init() {
    this.resultString = this.root + this.myString;
  }
}


@Injectable()
export class ChildService extends ParentService {
  constructor(){
    super();
  }
  init() {
    this.myString = "The Child";
    super.init();
  }
}