我目前收到以下错误:
EXCEPTION: No provider for Http! (Login -> AuthHttp -> Http)
AuthHttp是对Angular2-jwt的引用。这可能是一个问题吗?我已经盯着这一段时间了,我找不到可能出现的错误。
在我的login.ts中:
import {Component} from 'angular2/core';
import {
FORM_DIRECTIVES,
FormBuilder,
ControlGroup,
Validators,
AbstractControl,
Control
} from 'angular2/common';
import {Http, Headers} from 'angular2/http';
import {Router} from 'angular2/router';
import {ButtonRadio} from 'ng2-bootstrap/ng2-bootstrap';
import {AuthHttp, AuthConfig} from 'angular2-jwt';
import {AuthService} from '../../services/auth/authService';
import {AlertService} from '../../services/alerts/alertsService';
import {User} from '../../datatypes/user/user';
@Component({
selector: 'login',
template: require('./login.html'),
directives: [ ButtonRadio, FORM_DIRECTIVES ],
providers: [AuthService, AlertService, Http, AuthHttp]
})
在我的主题中:
document.addEventListener('DOMContentLoaded', function main() {
bootstrap(App, [
('production' === process.env.ENV ? [] : ELEMENT_PROBE_PROVIDERS),
HTTP_PROVIDERS,
ROUTER_PROVIDERS,
provide(LocationStrategy, { useClass: HashLocationStrategy }),
provide(AuthConfig, { useFactory: () => {
return new AuthConfig({
headerName: 'Authorization',
//headerPrefix: 'Bearer ',
tokenName: 'auth_token',
noJwtError: true
});
}}),
AuthHttp,
Http,
ConnectionBackend
])
.catch(err => console.error(err));
});
答案 0 :(得分:1)
您必须添加HTTP_BINDINGS
import {HTTP_BINDINGS} from 'angular2/http';
bootstrap(..., [
...
HTTP_BINDINGS,
...
]).catch(...);
答案 1 :(得分:0)
似乎这确实是Angular2-jwt的错误,或者至少是它的配置。 Here is the way it should be configured.
尽管如此,我还是设法清理了一些东西。如果这个问题实际上更深入,我会尝试重新打开。