How to change config for custom components?


#1

Hi all, i’m new at developing ionic2 apps. I’m trying to use “config.set(‘ios’, ‘tabSubPages’, ‘true’)” in one of my components but i can’t get the config changes.
I’m trying to use a service but:

  • when i call service method in MyApp component i can get correct config;
  • when i call the same method in another component (after the bootstrap) the method doesn’t do anything;
    How can a i change config while navigating in components app?

My goal is to show tabs only in certain pages and hide them in other ones.


#2

Can you post your code?


#3

app.ts:

import {Component, ViewChild} from ‘@angular/core’;
import {ionicBootstrap, Platform, Nav, Modal, Config} from ‘ionic-angular’;
import {StatusBar} from ‘ionic-native’;
import {TabHide} from ‘./services/tabHide’;
import {TabsPage} from ‘./pages/tabs’;

@Component({
templateUrl:“app.html”
})

export class MyApp {
@ViewChild(Nav) nav: Nav;

private rootPage:any;

constructor(private platform:Platform, public tabhide: TabHide ) {
this.rootPage = TabsPage;

platform.ready().then(() => {
  StatusBar.styleDefault();
  this.tabhide.changeVis();
});

}
}

ionicBootstrap(MyApp, [TabHide], {tabSubPages:false, scrollAssist:false});


chat-details.ts:

import {Component} from ‘@angular/core’;
import {NavController, NavParams, ViewController} from ‘ionic-angular’;
import {TabHide} from ‘…/…/services/tabHide’;

@Component({
templateUrl: ‘build/pages/chat-details/chat-details.html’,
})
export class ChatDetailsPage {
selectedConversation: any;
messages: Array<{text: string, date: string, from: string}>;

constructor(private nav: NavController,private viewCtrl: ViewController,navParams: NavParams
,public tabhide: TabHide){
tabhide.changeVis();
}
}


tabHide.ts:

import {Injectable} from ‘@angular/core’;
import {Config} from ‘ionic-angular’;

@Injectable()
export class TabHide {
private zone = new NgZone({enableLongStackTrace: false});

constructor(public config: Config) {
    console.log("creato tabHide");
}

public changeVis(){
    var tabsVisible = this.config.set('ios','tabSubPages','true');
}

}

This are 3 files of my project. When i call tabHide.changeVis() method in MyApp class i can set config properties but when i call the same method in ChatDetailsPage it doesn’t work.