【问题标题】:JHipster Service Provider ErrorJHipster 服务提供者错误
【发布时间】:2018-06-22 16:59:10
【问题描述】:

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

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

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

这些是.ts 文件。

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

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
}

【问题讨论】:

  • 错误文本在哪里?
  • 感谢您的宝贵时间,我忘记添加了。我做了修改,请检查。 @Gaël Marziou 我只发布了一个案例,因为第二个案例是相同的堆栈跟踪......很高兴你能帮助我,谢谢。
  • 你能帮帮我吗?
  • 所以你没有对 JHipster 生成的应用程序进行任何更改并且它不起作用?运行 4.13.3 吗?你能分享你的 git repo 或至少 .yo-rc.json 和 jdl 导入文件吗?
  • 我添加了.yo-rc.json 文件。我试图将 QuestionService 注入 QuizService 进行更改,但我的 JHipster 构建似乎没有收到更改。我更改了一些 html 文件只是为了测试它是否得到更改,结果是 JHipster 继续构建旧版本......我不知道为什么会发生这种情况。

标签: angular service jhipster provider


【解决方案1】:

与 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,也许这篇文章对某人有帮助,所以我决定分享一下。

特别感谢 Gael 的大力支持。 JHipster 是一款非常出色的产品,它的团队在支持和帮助方面绝对令人惊叹。

继续加油,伙计们!

【讨论】:

  • 如果您需要运行 sudo 则意味着您的设置错误,这样做非常危险,因为您从 Internet 下载未知软件(maven、npm)。在谷歌上搜索如何修复你的环境,节点使用 nvm,更改用户目录的所有权,...
猜你喜欢
  • 2017-10-08
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-07
  • 1970-01-01
  • 2021-05-19
  • 2019-01-01
相关资源
最近更新 更多