I have been using Ionic 1 for some time now and am ready to migrate to Ionic 2. Here is my problem, I am trying to get up to speed with Ionic 2 and all of the tutorial I find online are based on the what I guess is the beta version of the project that gets generated. Right off the bat I see that there is now an app.components.ts file, the Home Page constructor has a NavController, and the provider file that is generated does not contain the load() method any longer. I am trying to follow the following tutorial:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = HomePage;
constructor(platform: Platform) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
});
}
}
home.ts:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { PeopleService } from '../../providers/people-service/people-service';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [PeopleService]
})
export class HomePage {
public people: any;
constructor(public navCtrl: NavController, public peopleService: PeopleService) {
this.loadPeople;
}
loadPeople() {
this.peopleService.load()
.then(data => {
this.people = data;
});
}
}
** Note** The constructor line is giving me an error Cannot find name 'PeopleService’
I would assume that I need to add a reference to it somewhere but I do not know where or how. Any help is appreciated.
Move the providers declaration out of the component and into the app module. Your constructor also isn’t calling loadPeople (unless that’s some weird JavaScript quirk, I think you need parentheses after it).