作者:maniac0207 | 来源:互联网 | 2022-12-28 19:47
我在Angular 5中遇到HttpClient的问题。HttpClient在两个指定的组件上不发送任何请求(控制台中没有任何xhr登录)。在其他组件上,一切都很好。
从组件A调用ApiService POST方法(类似于HttpClient的包装程序的自定义服务),但是当我从组件B调用此方法时,
HttpClient似乎被冻结。
我的应用程序中有许多使用ApiService的组件。一切都注入良好。我不知道怎么了。
---回应
ApiService.ts
@Injectable()
export class ApiService
{
private errorListeners : Map any>> =
new Map any>>();
public constructor(private http: HttpClient)
{
}
public post(path : string, data : any, urlParams : any = null) : Observable
{
return this.http.post(`${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注入Component,HttpClient也无法正常工作
-同一模块示例调用中的其他组件:(有效)
public loginTraditionalMethod(emailAddress : string, plainPassword : string)
{
this.apiService.post('/auth/email', {
email: emailAddress,
password: plainPassword
}, {}).subscribe(res => {
console.log(res);
})
}
小智..
7
我遇到了同样的问题,订阅了之后没有xhr请求http.get()
。这是要求忘记密码功能的请求,因此我没有连接到该应用程序。
该请求被http令牌拦截器拦截,如果未检测到会话,该令牌将返回空的Observable。
永远不知道,这可能会帮助某人...
1> 小智..:
我遇到了同样的问题,订阅了之后没有xhr请求http.get()
。这是要求忘记密码功能的请求,因此我没有连接到该应用程序。
该请求被http令牌拦截器拦截,如果未检测到会话,该令牌将返回空的Observable。
永远不知道,这可能会帮助某人...