發現注射的名字我有一個單一視圖和供應商來處理API調用離子應用。該視圖只會顯示來自API的內容。 當我運行離子發球,我得到這個TS錯誤:Cannot find name 'ApiService'.
我的IDE是PHPStorm,當我在構造函數中點擊ApiService(這是紅色,說找不到這個名字),它重定向我的聲明正確的文件。 我有一個非常簡單的代碼與視圖組件:不能在離子2
import { Component } from '@angular/core';
import { NavController } from "ionic-angular";
import { ApiService } from "api-test"; // This is the class I have trouble with
@Component({
selector: 'cgu',
templateUrl: 'cgu.html'
})
export class cguView {
constructor(public navCtrl: NavController, private apiService: ApiService) {}
}
而且ApiService的代碼:
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Injectable } from '@angular/core';
@Injectable()
export class ApiService {
API_URL;
data;
constructor(public http: Http) {
this.API_URL = "myapi";
this.data = {};
}
call(action, entity, params) {
var link = this.API_URL;
var data = JSON.stringify({mydata});
this.http.post(link, data)
.subscribe(data => {
this.data.response = data;
console.log(data);
}, error => {
console.log("erreur!");
});
}
}
我缺少什麼?路徑是正確的(我把它放在同一個文件夾,以確保..)。預先感謝您的任何幫助
什麼是API測試? –
這是api-test.js文件 – saperlipopette
你的意思是'.ts'文件? –