I have a Ionic app with a single view and a provider to handle the API calls. This view would only display content from the API.
When I run Ionic serve, I get this TS error : Cannot find name 'ApiService'.
My IDE is PHPStorm, and when I click on ApiService in the constructor (which is in red and saying cannot find that name), it redirects me to the declaration in the right file.
I have a very simple code with a view component :
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) {}
}
And the code of the 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!");
});
}
}
What am I missing ? The path is right ( I put it in the same folder to be sure..).Thank you in advance for any help
The path is right ( I put it in the same folder to be sure..)
No its not.
When you give path as "api-test" it checks in node_modules for the package.
You need to give as:
import { ApiService } from "./api-test";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With