Angular callHooks not triggered when refresh page

809 Views Asked by At

i had problem when i use F5 button or directive call url from address bar ngOnInit not called properly.. I'm using debugger to see what happen, and the problem is callHook not triggered after ngOnInit..

I'm using Angular 9.1.2

This is my ngOnInit

ngOnInit(): void {
    console.log('fired OnInit');
    
    this.dtOptions = {
      pagingType : 'full_numbers',
      pageLength : 10
    };
    this.getCurrentUser();
    this.initializeList();
    this.resetFormData();
  }

and i'm using Ngx-Soap for call database, here's my service

import { Injectable } from '@angular/core';
import { Client, ISoapMethodResponse, NgxSoapService } from 'ngx-soap';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Document } from '../_models/document.model';
import { User } from '../_models/user.model';

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

  constructor(
    private soap : NgxSoapService
  ) {
    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))
   }

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

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

this is my image from Debugger, and those 3 yellow not called after ngOnInit

this is my console result

2

There are 2 best solutions below

1
On

After searching for awhile and test everything, so the answer is back to NgxSoap, the constructor of service not triggered and cause this error.. Still looking why this constructor not triggered at NgxSoap github.. Thanks all..

4
On

Show what error the Chrome DevTools console gives you.