我在Angular5中有HTTPCLIENT的问题。HttpClient在两个指定的组件上没有发送任何请求(我在控制台中没有任何XHR log(。在其他组件上,一切都很好。
调用component a 的Apiservice Post Method(自定义服务,就像httpclient一样(HTTPClient似乎被冷冻。
我的应用程序中有许多使用Apiservice的组件。一切都很好。我不知道怎么了。
---响应
apiservice.ts
@Injectable()
export class ApiService
{
private errorListeners : Map<string, Array<(details ?: any) => any>> =
new Map<string, Array<(details ?: any) => any>>();
public constructor(private http: HttpClient)
{
}
public post<T>(path : string, data : any, urlParams : any = null) : Observable<any>
{
return this.http.post<T>(`${environment.api.path}${path}`, data, {
params: urlParams
}).catch(this.catchErrors()).map(response => {
if (response['Error']){
throw response['Error'];
}
return response;
});
}
}
- 组件
@Component({
selector: 'login-register-component',
templateUrl: './register.component.html',
styleUrls: [
'./../../assets/main/css/pages/login.css'
]
})
export class RegisterComponent implements OnInit, OnDestroy
{
public constructor(private route: ActivatedRoute,
private router: Router,
private userService : UserService,
private apiService: ApiService
)
{
this.apiService.post('/some-endpoint', null, {}).subscribe(res => {
console.log(res);
}(;
}
httpclient即使我直接将httpclient注入组件
也不起作用- 同一模块中的其他组件示例调用:(它有效(
public loginTraditionalMethod(emailAddress : string, plainPassword : string)
{
this.apiService.post('/auth/email', {
email: emailAddress,
password: plainPassword
}, {}).subscribe(res => {
console.log(res);
})
}
我遇到了相同的问题,在订阅 http.get()
后没有XHR请求。这是忘记密码功能的请求,因此我没有连接到该应用程序。
该请求是由HTTP令牌拦截器拦截的,如果未检测到会话,该请求将返回空心观察。
永远不会知道,这可能会帮助某人...