【发布时间】: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
【问题讨论】:
-
听起来
ngOnInit()正在开火,但在那些callHooks 中应该发生什么不起作用? -
callHooks在ngOnInit()触发后被跳过,所以refreshView将执行leaveView()因为callHooks未检测到任何更改 -
听起来项目/组件可能有些奇怪。如果您在 stackblitz 中有一个可行的示例,则更容易找出问题所在。
标签: angular typescript ngoninit