0

I encountered a problem that probably has a simple solution that I'm sadly ignoring. I hope someone will help me.

Basically I generated a new app with a .jdl file that perfectly did the work.

Now I'm trying to use this simple app but I get an error while clicking on "Add {Entity Name}". 2 entities give me this error.

These are .ts files.

The first is Quiz entity that has a relationship with 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 is made in the same way as 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 {...}

I only paste these ones because the problem is the same in the 2 entities.

I thought that the problem was in app.module.ts so I made providers' imports but this didn't solve the problem.

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 {}

What am I missing?

EDIT:

Error log:

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 file here.

{
  "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
  }
}

I add JDL here.

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
}
Gozus19
  • 165
  • 19
  • Where is the text of the error? – Gaël Marziou Jan 13 '18 at 14:06
  • Thank you for your time, I forget to add it. I made an edit, please check it. @Gaël Marziou I only posted one case because the second one is the same stack trace... Glad if you help me, thanks. – Gozus19 Jan 13 '18 at 14:14
  • Could you please help me out there? – Gozus19 Jan 14 '18 at 13:58
  • So you made no changes to app generated by JHipster and it does not work? Running 4.13.3 ? Could you share your git repo or at least .yo-rc.json and jdl import file? – Gaël Marziou Jan 14 '18 at 15:16
  • I added the `.yo-rc.json` file. I tried to make changes injecting QuestionService into QuizService but my JHipster build seems to not receive changes. I changed a bit the html files just to test if it gets changes and the result is that JHipster continues to build older version... I don't know why this happens. – Gozus19 Jan 14 '18 at 15:20
  • I am building project with `mvn -Pdev` command. – Gozus19 Jan 14 '18 at 15:20
  • JDL file please – Gaël Marziou Jan 14 '18 at 15:22
  • First you should use both mvnw and yarn to see hot reloading of changes in client part. See doc http://www.jhipster.tech/using-angular/ – Gaël Marziou Jan 14 '18 at 15:24
  • I added JDL file. If I run yarn start it doesn't take Dev profile... I rebuild the project every time I make a change using mvn. Thanks for your patience. – Gozus19 Jan 14 '18 at 15:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/163146/discussion-between-gael-marziou-and-manuel-gozzi). – Gaël Marziou Jan 14 '18 at 15:37

1 Answers1

0

Talking with G. Marziou helped me to find the solution.

There were different problems.

1) Launching build with terminal command without sudo didn't compile all the files due to an EACCES hidden error (terminal didn't show that).

2) Once launched the console gave the error of a generated component.ts file. It seems that JHipster generated this code:

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

that I edited removing providers.

Once done I built it and it worked. I'm using MAC OS Sierra, maybe this post can be helpful for someone, so I decided to share the same.

Special thanks to Gael for his amazing support. JHipster is a very well done product, its team is absolutely amazing in supporting and assistance.

Keep it up, guys!

Gozus19
  • 165
  • 19
  • If you need to run sudo then it means your setup is wrong and doing so is very dangerous because you download unknown software from the internet (maven , npm). Search on google about how to fix your environment, for node use nvm, change ownership of your user directories, ... – Gaël Marziou Jan 14 '18 at 20:05