I am facing an issue where I am unable to pass a value from the Tabs component to the Task component. To address this, I have created a separate data service. The value in the Tabs component is obtained as a parameter from another component. However, when trying to pass this value from Tabs to the Task component, it returns 'undefined' on the Task Page.
Below is my Service class
import { Injectable} from '@angular/core';
@Injectable()
export class DataService {
list:any;
getUserData(){
return this.list;
}
setUserData(data:any){
this.list = data;
}
}
Tabs Component
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { SettingsPage } from '../settings/settings';
import { TasksPage } from '../tasks/tasks';
import { DataService } from "../../services/data.service";
@Component({
templateUrl: 'tabs.html',
providers:[DataService]
})
export class TabsPage {
tab1Root = TasksPage;
tab2Root = SettingsPage;
user:any;
constructor(public navCtrl: NavController, public navParams: NavParams,public dataService: DataService) {
this.user = navParams.get('param1');
this.dataService.setUserData(this.user);
}
}
Task Page
import { Component,ViewChild } from '@angular/core';
import { DataService } from "../../services/data.service";
import { TabsPage } from '../tabs/tabs';
import { TasksCreatePage } from '../tasks-create/tasks-create';
const logger = new Logger('Tasks');
@Component({
selector: 'page-tasks',
templateUrl: 'tasks.html',
providers:[DataService]
})
export class TasksPage {
usern:any;
constructor(public dataService: DataService){
this.usern = this.dataService.getUserData();
console.log(this.usern);
}