Skip to content

Client Undefined #94

@moh-ari-novan

Description

@moh-ari-novan

Hi Lula, i had some problem when i refresh page on some component, it says Cannot read property 'call' of undefined

this is my App Module

//Other Module
import { NgxSoapModule } from 'ngx-soap';
@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    //Other Module
    NgxSoapModule,
  ],
  providers: [
    {
      
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

this is my Component ts

import { Component, OnInit, AfterViewInit, ViewChild, OnDestroy } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { GeneralService } from 'src/app/_services/general.service';

@Component({
  selector: 'app-document',
  templateUrl: './document.component.html',
  styles: [
  ]
})
export class DocumentComponent implements OnInit {
  //Variable Declaring
  
  //Dependency Injection
  constructor(
    private fb : FormBuilder,
    private service : GeneralService,
  ) { }

  //Initialization
  ngOnInit(): void {
    console.log('fired OnInit');
    
    this.initializeList();
    this.resetFormData();
  }

  //Func
  get f() { return this.formData.controls; }

  //Func
  initializeList() : void {
   this.getCategoryList();
    this.getJobTitleList();
  }

  //Func
  getCategoryList(){
    this.service.GetCategoryList().subscribe(res=>{      
      this.categoryList = res.result.GetCategoryListResult.CategoryList;
    })
  }

  //Func
  getJobTitleList(){
    this.service.GetAllJobTitle().subscribe(res=>{
      this.jobTitleList = res.result.GetAllJobTitleResult.JobTitleVM;
    })
  }

and this is my Service

import { Injectable } from '@angular/core';
import { Client, ISoapMethodResponse, NgxSoapService } from 'ngx-soap';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';

@Injectable({
  providedIn: 'root'
})
export class GeneralService {
  client : Client;

  constructor(
    private soap : NgxSoapService
  ) {
   //this function always skipped only when i reload Document Component
    this.soap.createClient(environment.wsURL).then(client=>{
      client.addSoapHeader({
        'tns:ModuleCredential':{
          'tns:ModuleAppName':'xxxx',
          'tns:ModuleUserName':'xxxx',
          'tns:ModulePassword':'xxxx'
        }  
      });
      client.addHttpHeader(
        'Content-Type','text/xml; charset=utf-8'
      );
      this.client = client;
    })
    .catch(err=>console.log('SoapError',err))
   }

  GetCategoryList():Observable<ISoapMethodResponse>{
    const body ={
      data : null
    };
    return this.client.call('GetCategoryList',body);
  }  

every time i refresh or reload page i've got this error

ERROR TypeError: Cannot read property 'call' of undefined
    at GeneralService.GetCategoryList (general.service.ts:44)
    at DocumentComponent.getCategoryList (document.component.ts:104)
    at DocumentComponent.initializeList (document.component.ts:91)
    at DocumentComponent.ngOnInit (document.component.ts:69)
    at callHook (core.js:4726)
    at callHooks (core.js:4690)
    at executeInitAndCheckHooks (core.js:4630)
    at refreshView (core.js:12026)
    at refreshEmbeddedViews (core.js:13404)
    at refreshView (core.js:12035)

the constructor always not triggered

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions