コンポーネントでサービスをインスタンス化しようとしています。私はこのエラーを得たサービスコンストラクタにパラメータを渡しますか?
Uncaught Error: Can't resolve all parameters for AuthenticationService: (?, [object Object], ?).
これは私のサービス
@Injectable()
export class AuthenticationService {
protected basePath = 'http://localhost:8080/rest';
public defaultHeaders: Headers = new Headers();
public configuration: Configuration = new Configuration();
constructor(protected http: Http, @Optional() @Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
if (basePath) {
this.basePath = basePath;
}
if (configuration) {
this.configuration = configuration;
this.basePath = basePath || configuration.basePath || this.basePath;
}
}
public login(authenticationkey?: string, body?: AuthenticationRequestHolder, extraHttpRequestParams?: any): Observable<AuthenticationBundle> {
return this.loginWithHttpInfo(authenticationkey, body, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
} else {
return FlexiCoreDecycl`enter code here`e.retrocycle(response.json()) || {};
}
});
}
// More Code
であり、これはサービスに
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
constructor(private _authenticationService: AuthenticationService) {
}
ngOnInit() {
this._authenticationService
.login('', {mail: '[email protected]', password: 'admin'})
.subscribe(response => {
console.log(response);
},
error => {
console.log(error);
});
}
}
を使用するコンポーネントであり、ここで、角度モジュール
@NgModule({
declarations: [
AppComponent,
LoginComponent
],
imports: [
BrowserModule
],
providers: [AuthenticationService],
bootstrap: [AppComponent]
})
export class AppModule { }
にあります
誰も助けてくれますか?適切に配線しますか?私は角と形の両方のために新しいので、私は少し説明とポインタを感謝します。
のように私のapp.module lokesは、私は私がにサービスを登録しようとしているときに問題が起こっていると信じて、あなたの提案を追加し、いくつかの研究をしましたが、問題はまだそこにあるものですプロバイダ。私はそれらを並べ替えることを試みたが、何も変わらなかった。 – Hanoch
@Hanochプロジェクトをいくつかのgitリポジトリにアップロードできますか? –
できません。私が持っている問題は、プロバイダに "AuthenticationService"を登録できないということです。私は新しいプロジェクトを開始した後、サービスを追加して登録しようとしました。私は別のコンポーネントでそれを使用しようとしていません。 – Hanoch