So I’m trying to get working from scratch an app for my Wordpress site. I’m using this tutorial: 10 Minutes with Ionic 2: Calling an API - Ionic Blog
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, ) {
}
}