[solved] Typescript transpiler unable to find a service name


#1

So I’m trying to get working from scratch an app for my Wordpress site. I’m using this tutorial: http://blog.ionic.io/10-minutes-with-ionic-2-calling-an-api/
Problem is, that typescript prints an error Cannot find name 'WordpressService'.
wordpress-service.ts:

import { Injectable } from ‘@angular/core’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;

/*
  Generated class for the WordpressService provider.
  See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  for more info on providers and Angular 2 DI.
*/
@Injectable()
export class WordpressService {
data: any;
load(){
  if (this.data){
  //already loaded data
  return Promise.resolve(this.data);
}
//don't have the data yet
return new Promise(resolve => {
//we are using Angular Http provider to request the data,
//then on a response, it'll map the JSON data to parsed JS object
//next, we process the data and resolve the promise with the new data.
this.http.get('http://localhost:61588/wp-json/wp/v2/posts')
.map(res => res.json())
.subscribe(data => {
  //we've got the raw data, now generate the core schedule data and save the data for later reference
  this.data = data;
  resolve(this.data);
});
}
)
}
  constructor(public http: Http) {
    console.log('Hello WordpressService Provider');
  }
}

about.ts

import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { WordpressService } from ‘…/providers/wordpress-service/wordpress-service’
@Component({
selector: ‘page-about’,
templateUrl: ‘about.html’,
providers: [WordpressService]
})

export class AboutPage {
items: any;
private jsonURL = ‘http://localhost:61588/wp-json/wp/v2/posts’;
public wordpress: any;
public wordpressService: WordpressService;

constructor(public navCtrl: NavController, ) {

}

}


#2

Wow, that generator code is just dreadful. That aside, get rid of the providers bit of the @Component decorator and move it into the AppModule.


#3

Typescript error solved. That was caused by wrong path (because, there is no additional folder in providers folder) :cold_sweat:


#4

Please explain this.


#5

Understood the solution.