2017-06-29 68 views
0

我有angular2 v 2.4.0的問題,當我嘗試導入類時,它叫我TS2304:找不到名字'HTTPTestService'(類的名稱)代碼component.ts找不到名字'myobject'Angular2

import { Component } from '@angular/core'; 
import { PictureRegister } from '../student.data'; 
import { HTTPTestService } from 'json.service'; 
@Component({ 
moduleId: module.id.toString(), 
    selector: 'student-register', 
    templateUrl: 'student-register.component.html', 
    providers: [ 
     PictureRegister, 
     HTTPTestService 
    ] 
}) 
export class StudentRegisterComponent { 
    constructor( 
       pictureRegister: PictureRegister, 
       httpJSON: HTTPTestService //Here is error 
) 

和service.ts

import {Injectable} from '@angular/core'; 
@Injectable() 
export class HTTPTestService{ 
    constructor (_http: Http) 
    { 
     this.httpJSON = _http; 
    } 
//etc 
} 

我也得到了第二類文件,效果很好,但我不想把所有的類成,你能幫助我嗎?

+1

因爲你導入不好。嘗試使用'./service.ts'中的'import {HTTPTestService};' – trichetriche

+0

該文件名爲json.service.ts? – thardes2

回答

1
import { HTTPTestService } from './json.service'; 
+0

非常感謝,現在運作良好:) –