首页 > 解决方案 > 刷新页面时未触发 Angular callHooks

问题描述

当我使用F5 按钮或来自地址栏ngOnInit 的指令调用 url 未正确调用时,我遇到了问题。我正在使用调试器查看发生了什么,问题是在 ngOnInit 之后未触发 callHook 。

我正在使用 Angular 9.1.2

这是我的 ngOnInit

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

我正在使用 Ngx-Soap 作为呼叫数据库,这是我的服务

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);
  }  

这是我来自 Debugger 的图像,在 ngOnInit 之后没有调用那 3 个黄色

这是我的控制台结果

标签: angulartypescriptngoninit

解决方案


显示 Chrome DevTools 控制台给你的错误。


推荐阅读