Is it possible to call a function in another controller within Ionic 2? Here is my code where I want to call the loadPeople function in the tab controller.
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'
})
export class HomePage {
constructor(public navCtrl: NavController, public peopleService: PeopleService) {
this.loadPeople();
}
loadPeople(){
this.peopleService.load()
.then(data => {
this.people = data;
});
}
}
tabs.ts
import { Component } from '@angular/core';
import { HomePage } from '../home/home';
import { AboutPage } from '../about/about';
import { ContactPage } from '../contact/contact';
@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
// this tells the tabs component which Pages
// should be each tab's root Page
tab1Root: any = HomePage;
tab2Root: any = AboutPage;
tab3Root: any = ContactPage;
constructor() {
}
}
In tabs.ts, how can I call the loadPeople function when a tab is selected?