Skip to content

Instantly share code, notes, and snippets.

@prantikv
Forked from adamkearsley/tabs.service.ts
Created January 24, 2018 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prantikv/72874e844d275be942ee3f50e12f69f7 to your computer and use it in GitHub Desktop.
Save prantikv/72874e844d275be942ee3f50e12f69f7 to your computer and use it in GitHub Desktop.
A service to hide and show tabs in Ionic 2
import {Injectable} from '@angular/core';
// Declare TabsService as a provider in app.module.ts
// Inject TabsService in your class: constructor(public tabs: TabsService){}
// Use the this.tabs.hide() or this.tabs.show() methods wherever you want
@Injectable()
export class TabsService {
constructor() {}
public hide() {
let tabs = document.querySelectorAll('.tabbar');
let footer = document.querySelectorAll('.footer');
let scrollContent = document.querySelectorAll('.scroll-content');
if (tabs !== null) {
Object.keys(tabs).map((key) => {
tabs[key].style.transform = 'translateY(56px)';
});
// fix for removing the margin if you got scorllable content
setTimeout(() =>{
Object.keys(scrollContent).map((key) => {
scrollContent[key].style.marginBottom = '0';
});
Object.keys(footer).map((key) => {
footer[key].style.bottom = '0px';
});
})
}
}
public show() {
let tabs = document.querySelectorAll('.tabbar');
if (tabs !== null) {
Object.keys(tabs).map((key) => {
tabs[key].style.transform = 'translateY(0px)';
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment