【问题标题】:Angular callHooks not triggered when refresh page刷新页面时未触发 Angular callHooks
【发布时间】:2021-03-18 10:26:41
【问题描述】:

当我使用 F5 按钮或来自地址栏的指令调用 url 时遇到问题 ngOnInit 未正确调用。我正在使用调试器查看发生了什么,问题是在 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);
  }  

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

this is my console result

【问题讨论】:

  • 听起来ngOnInit() 正在开火,但在那些callHooks 中应该发生什么不起作用?
  • callHooksngOnInit() 触发后被跳过,所以refreshView 将执行leaveView() 因为callHooks 未检测到任何更改
  • 听起来项目/组件可能有些奇怪。如果您在 stackblitz 中有一个可行的示例,则更容易找出问题所在。

标签: angular typescript ngoninit


【解决方案1】:

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

【讨论】:

【解决方案2】:

搜索了一会儿,测试了一切,所以答案又回到了NgxSoap,服务的构造函数没有触发,导致这个错误.. 仍在寻找为什么这个构造函数没有在 NgxSoap github 上触发.. 谢谢大家。。

【讨论】:

    猜你喜欢
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    相关资源
    最近更新 更多