Search code examples
angularopenapi-generator

Angular 16 issue with ng-openapi-gen


I have an issue with ng-openapi-gen and angular 16 I do not understand.

I have an api I have generated the client part from my server using ng-open-api. I created the ng app and trying to use the API.

When in app.component.ts I have:

import { Component } from '@angular/core';
import { ApiService} from './api/services/api.service'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'ngClient';
  }

All works fine and when I am adding the constructor like shown below:

...
export class AppComponent {
  title = 'ngClient';
  constructor(private apiService: ApiService) {  }
}
...

The html page does not show anymore with errors in browser dev tools: errors

Did anyone faced this already?

Any help would be greatly appreciated.

Thank you


Solution

  • This has been resolved modifying app.module.ts like shown below:

    ...
        import { ApiModule } from './api/api.module';
        import { HttpClientModule } from '@angular/common/http';
    ...
    

    and

    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        ...
        HttpClientModule,
        ApiModule.forRoot({ rootUrl: 'http://localhost:3000/api' }),