Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transferhttp is not wokring #72

Closed
shahbazkhan054 opened this issue Jan 12, 2019 · 5 comments
Closed

Transferhttp is not wokring #72

shahbazkhan054 opened this issue Jan 12, 2019 · 5 comments

Comments

@shahbazkhan054
Copy link

I am using transferHttpService in apiService and subscribing it from ngOnInit.
My SSR is not waiting for service to complete and source is coming without the code.

@Gorniv
Copy link
Member

Gorniv commented Jan 14, 2019

Do you use absolute URL for the request?
You need to reproduce the problem with the public repository.

@shahbazkhan054
Copy link
Author

Hi Gorvin,

Thank you for your reply and suggestion. But it doesn't work even after ensuring absolute path.

Please find code snippets :

component :

self.apiService.get('getPapersOfBoard', 'boardName=' + self.boards.toUpperCase()).subscribe(res => {
        self.apiService.list('getSubjectDescription').subscribe(result => {
          result['sujectDescription'].forEach(element => {
            res.boardName['class'].forEach(cl => {
              cl['subject'].forEach(sub => {
                if (sub.name === element.subject_id.name && cl.name === element.class_id.name
                  && self.boards.toUpperCase() === element.board_id.name) {
                  sub.description = element.description;
                  sub.title = element.title;
                }
              });
            });
          });
          self.apiService.setData(res.boardName);
          self.getTree(params);
          self.spinner.hide();
        });
      });

Apiservice.ts

constructor(private httptransfer: TransferHttpService, @Inject('ORIGIN_URL') public baseUrl: string,) { }
.....

 get(modelName: string, id: string): Observable<any> {
    return this.httptransfer.get(environment.apiEndpoint.concat(modelName).concat('?').concat(id));
  }

  list(modelName: string, criteria = {}, limit = '1000', skip = '0', sort = 'updatedAt DESC'): Observable<any> {
    const listOptions = new HttpHeaders();
    return this.httptransfer.get(environment.apiEndpoint.concat(modelName));
  }

environment.ts

export const environment = {
  production: false,
  apiEndpoint: 'http://0.0.0.0:3000/api/',
  isServer: true,
  // for prerender
  host: 'http://localhost:4200/',
};

Can you please help me out with this?

@shahbazkhan054
Copy link
Author

Dependency injection issue solved.

@Gorniv
Copy link
Member

Gorniv commented Jan 17, 2019

@shahbazkhan054 can you write more information about the solution?

@shahbazkhan054
Copy link
Author

shahbazkhan054 commented Jan 17, 2019

Changes I made to fix the issue :

  1. The TransferHttpModule and transferHttpService should be used in one module.
    I removed TransferHttpModule from shared module to AppModule and also add provider as transferHttpService and apiService.
  2. Typescript version : 3.1.1 -> 3.1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants