2017-02-17 55 views
0

我已經從 http://courses.angularclass.com/courses/enrolled/73288錯誤:無法解析NoteService所有參數:

以下的角2的視頻教程和上面提到的錯誤出現,當我跑我的API(?)。

以下是根據瀏覽器的服務有未解決的參數

`

import {Injectable} from '@angular/core'; 
import { ApiService } from './api'; 


export class NoteService{ 
    path: string= '/notes'; 
    constructor(private api: ApiService) {} 
    createNote(note){ 
     return this.api.post(this.path, note); 
    } 
    getNotes(){ 
     return this.api.get(this.path); 
    } 

    completeNote(note){ 
     return this.api.delete(`${this.path}/${note.id}`); 
    } 
}` 

,這是網頁中的API服務,

`

import {Injectable} from '@angular/core'; 
import {Headers, Http, Response} from '@angular/http'; 
import {Observable} from 'rxjs/Observable'; 
import 'rxjs/Rx'; 
import 'rxjs/add/observable/throw'; 

@Injectable() 
export class ApiService{ 
    headers: Headers=new Headers({ 
     'Cotent-Type': 'application/json', 
     Accept: 'application/json' 
    }); 

    api_url: string = 'http://localhost:3500'; 

    constructor(private http: Http){ 

    } 

    private getJson(resp: Response){ 
     return resp.json(); 
    } 
    private checkForError(resp: Response): Response{ 
     if(resp.status >=200 && resp.status<300){ 
      return resp; 
     } 
     else{ 
      const error=new Error(resp.statusText); 
      error['response']= resp; 
      console.error(error); 
      throw error; 
     } 
    } 
    get(path: string): Observable<any>{ 
     return this.http.get(`${this.api_url}${path}`, this.headers) 
     .map(this.checkForError) 
     .catch(err=> Observable.throw(err)) 
     .map(this.getJson) 
    } 

    post(path: string, body): Observable<any>{ 
     return this.http.post(
       `${this.api_url}${path}`, 
       JSON.stringify(body), 
       {headers: this.headers} 
     ) 
     .map(this.checkForError) 
     .catch(err=> Observable.throw(err)) 
     .map(this.getJson); 
    } 
    delete(path: string): Observable<any>{ 
     return this.http.delete(`${this.api_url}${path}`, this.headers) 
     .map(this.checkForError) 
     .catch(err=> Observable.throw(err)) 
     .map(this.getJson) 
    } 
} 

`

如果問題中應包含任何其他文件,請在評論中提及它。 謝謝。

+0

你在哪裏提供'ApiService'和'NoteService'?你導入了'HttpModule'嗎? –

回答

0
@Injectable() // required when a service has constructor parameters 
export class NoteService{ 
相關問題