2016-07-06 3 views
1

http.get 요청을 만드는 서비스를 구성 요소에 삽입하는 코드가 있습니다.Angular 2 Typescript - TooltipService의 모든 매개 변수를 확인할 수 없습니다.

구성 요소가 잘 렌더링되지만 구성 요소에 서비스를 삽입하면 오류가 발생합니다.

그리고 오류가 발생합니다.

예외 : 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)); 

답변

2

당신은 당신의 코드에서 2 오타가 있습니다.

그것은 HTTP, Http 아니다 :

export class TooltipService { 
    constructor(public http: Http) {} 

당신은 아마 서비스를 주입 할 아닌 구성 요소 :

export class TooltipComponent implements OnInit { 
    @Input() explaination: boolean; 
    @Input() nodeId: number; 
    @Input() questionId: number; 

    constructor(public tooltipService: TooltipService) {} 
+0

롤 –

+1

최고의 일어나는 바보 어떤 실수! :) – rinukkusu

+0

질문을 풀기 위해 대답을 수락 하시겠습니까? – rinukkusu

관련 문제