1
我有這個代碼注入一個服務,它使一個http.get請求成爲一個組件。Angular 2 Typescript - 無法解析TooltipService的所有參數
該組件呈現正常,但是當我將服務注入組件時出現錯誤。
並得到錯誤;
EXCEPTION:無法解析TooltipService的所有參數:(?)。
我已經包含了自舉,因爲我相信它是一個DI問題,
import { Component, Input } from '@angular/core';
import { TooltipService } from '../../services/tooltip/tooltip.service';
@Component({
..,
..,
providers: [TooltipService]
})
export class TooltipComponent implements OnInit {
@Input() explaination: boolean;
@Input() nodeId: number;
@Input() questionId: number;
constructor(public tooltipService: TooltipComponent) {}
ngOnInit() {
if(this.explaination) {
this.tooltipService.getExplaination(this.nodeId, this.questionId)
.then(response => console.log(response));
}
}
}
-
import { Http } from '@angular/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class TooltipService {
constructor(public http: HTTP) {}
getExplaination(private nodeId: number, private questionId: number) {
let url = `someUrl/`
+ questionId + `/` + nodeId;
return this.http.get(url)
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}
}
-
import { bootstrap } from '@angular/platform-browser-dynamic';
import { disableDeprecatedForms, provideForms } from '@angular/forms';
import { HTTP_PROVIDERS } from '@angular/http';
import {AppComponent} from '../app/components/app/app.component';
bootstrap(AppComponent, [
HTTP_PROVIDERS,
disableDeprecatedForms(),
provideForms()
])
.catch((err: any) => console.error(err));
洛爾多麼愚蠢的錯誤 –
偏偏是最好的! :) – rinukkusu
你介意接受解決問題的答案嗎? – rinukkusu