HttpClient Angular 5不发送请求

Rev*_*rze 4 ajax httpclient typescript angular angular5

我在Angular 5中遇到HttpClient的问题。HttpClient在两个指定的组件上不发送任何请求(控制台中没有任何xhr登录)。在其他组件上,一切都很好。

从组件A调用ApiService POST方法(类似于HttpClient的包装程序的自定义服务),但是当我从组件B调用此方法时, 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;
        });
    }

}
Run Code Online (Sandbox Code Playgroud)

- 零件

   @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);
Run Code Online (Sandbox Code Playgroud)

});

}
Run Code Online (Sandbox Code Playgroud)

即使我直接将Ht​​tpClient注入Component,HttpClient也无法正常工作

-同一模块示例调用中的其他组件:(有效)

public loginTraditionalMethod(emailAddress : string, plainPassword : string)
    {

        this.apiService.post('/auth/email', {
            email: emailAddress,
            password: plainPassword
        }, {}).subscribe(res => {
           console.log(res);
        })

    }
Run Code Online (Sandbox Code Playgroud)

小智 7

我遇到了同样的问题,订阅了之后没有xhr请求http.get()。这是要求忘记密码功能的请求,因此我没有连接到该应用程序。

该请求被http令牌拦截器拦截,如果未检测到会话,该令牌将返回空的Observable。

永远不知道,这可能会帮助某人...