JHipster服务提供商错误

时间:2018-01-13 12:02:55

标签: angular service jhipster provider

我遇到了一个可能有一个简单的解决方案的问题,我很遗憾地忽略了这个问题。我希望有人能帮助我。

基本上我生成了一个带有.jdl文件的新应用程序,完美地完成了工作。

现在我正在尝试使用这个简单的应用程序但是在点击“添加{实体名称}”时出现错误。 2个实体给我这个错误。

这些是.ts个文件。

第一个是与Quiz有关系的Question实体。

quiz.service.ts

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../app.constants';
import { Quiz } from './quiz.model';
import { ResponseWrapper, createRequestOption } from '../../shared';

@Injectable()
export class QuizService {...}

question.service.ts的制作方式与quiz.service.ts

相同
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../app.constants';

import { Question } from './question.model';
import { ResponseWrapper, createRequestOption } from '../../shared';

@Injectable()
export class QuestionService {...}

我只粘贴这些,因为2个实体的问题是相同的。

我认为问题发生在app.module.ts,所以我提供了供应商的进口,但这并没有解决问题。

app.module.ts

import './vendor.ts';

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Ng2Webstorage } from 'ngx-webstorage';

import { ConductionTestsSharedModule, UserRouteAccessService } from './shared';
import { ConductionTestsAppRoutingModule} from './app-routing.module';
import { ConductionTestsHomeModule } from './home/home.module';
import { ConductionTestsAdminModule } from './admin/admin.module';
import { ConductionTestsAccountModule } from './account/account.module';
import { ConductionTestsEntityModule } from './entities/entity.module';
import { customHttpProvider } from './blocks/interceptor/http.provider';
import { PaginationConfig } from './blocks/config/uib-pagination.config';

import { UserProfileService } from './entities/user-profile/user-profile.service';
import { QuestionService } from './entities/question/question.service';
import { PositionService } from './entities/position/position.service';
import { CustomUserService } from './entities/custom-user/custom-user.service';
import { QuizService } from './entities/quiz/quiz.service';
import { ResultService } from './entities/result/result.service';
import { RoleService } from './entities/role/role.service';

// jhipster-needle-angular-add-module-import JHipster will add new module here

import {
    JhiMainComponent,
    NavbarComponent,
    FooterComponent,
    ProfileService,
    PageRibbonComponent,
    ErrorComponent
} from './layouts';

@NgModule({
    imports: [
        BrowserModule,
        ConductionTestsAppRoutingModule,
        Ng2Webstorage.forRoot({ prefix: 'jhi', separator: '-'}),
        ConductionTestsSharedModule,
        ConductionTestsHomeModule,
        ConductionTestsAdminModule,
        ConductionTestsAccountModule,
        ConductionTestsEntityModule,
        // jhipster-needle-angular-add-module JHipster will add new module here
    ],
    declarations: [
        JhiMainComponent,
        NavbarComponent,
        ErrorComponent,
        PageRibbonComponent,
        FooterComponent
    ],
    providers: [
        ProfileService,
        customHttpProvider(),
        PaginationConfig,
        UserRouteAccessService,
        UserProfileService,
        QuestionService,
        PositionService,
        CustomUserService,
        QuizService,
        ResultService,
        RoleService
    ],
    bootstrap: [ JhiMainComponent ]
})
export class ConductionTestsAppModule {}

我错过了什么?

修改

错误日志:

ERROR Error: StaticInjectorError[QuestionService]: 
  StaticInjectorError[QuestionService]: 
    NullInjectorError: No provider for QuestionService!
    at _NullInjector.get (core.js?593e:993)
    at resolveToken (core.js?593e:1281)
    at tryResolveToken (core.js?593e:1223)
    at StaticInjector.get (core.js?593e:1094)
    at resolveToken (core.js?593e:1281)
    at tryResolveToken (core.js?593e:1223)
    at StaticInjector.get (core.js?593e:1094)
    at resolveNgModuleDep (core.js?593e:10883)
    at NgModuleRef_.get (core.js?593e:12111)
    at resolveDep (core.js?593e:12609)

.yo-rc.json在此处提交。

{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "it.manuelgozzi.conductiontest"
    },
    "jhipsterVersion": "4.13.2",
    "baseName": "ConductionTests",
    "packageName": "it.manuelgozzi.conductiontest",
    "packageFolder": "it/manuelgozzi/conductiontest",
    "serverPort": "8080",
    "authenticationType": "session",
    "cacheProvider": "no",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "enableSwaggerCodegen": false,
    "rememberMeKey": "cdda7ac3158dc63769dac817269341c665e771fb",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "monolith",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": false
  }
}

我在这里添加了JDL。

entity Role {
    roleName String
}

entity CustomUser {
    password String,
    enabled Boolean,
}

entity UserProfile {
    firstName String,
    lastName String,
    email String,
    contact String,
    domain String,
    expLevel Integer
}

entity Position {
    description String,
    domain String,
    status String,
    createdBy String,
    createdOn LocalDate
}

entity Quiz {
    startDate LocalDate,
    endDate LocalDate,
    status String,
    marks String
    questionsNumber Integer,
    complexity String
}

entity Question {
    section String,
    description String,
    optionA String,
    optionB String,
    optionC String,
    optionD String,
    answer String,
    marks String,
    status String,
    complexity String
}

entity Result {
    obtainedMarks String,
    percentage Double,
    appearedOn String,
}

relationship ManyToOne {
    CustomUser{position} to Position
}

relationship ManyToMany {
    Quiz{questions} to Question
}

relationship OneToOne {
    CustomUser{userProfile} to UserProfile{customUser}
}

relationship ManyToOne {
    CustomUser{role} to Role
}

relationship OneToMany {
    Position{quiz} to Quiz
}

relationship OneToOne {
    Quiz{result} to Result{quiz}
}

relationship ManyToOne {
    Question{quiz} to Quiz
}

1 个答案:

答案 0 :(得分:0)

与G. Marziou交谈帮助我找到解决方案。

有不同的问题。

1)使用没有sudo的终端命令启动构建时,由于EACCES隐藏错误(终端没有显示),所以没有编译所有文件。

2)一旦启动,控制台就会生成component.ts文件的错误。 似乎JHipster生成了这段代码:

@Component({
    selector: 'jhi-user-profile',
    templateUrl: './path of the template',
    providers: [NameOfTheService]
})

我编辑了删除providers

一旦完成,我就建立了它并且它有效。我正在使用MAC OS Sierra,也许这篇文章对某人有帮助,所以我决定分享同样的内容。

特别感谢盖尔的出色支持。 JHipster是一款做得很好的产品,它的团队在支持和帮助方面绝对令人惊叹。

坚持下去,伙计们!