core114
core114

Reputation: 5335

Ionic-3 error Cannot read property 'style' of null

Im Used Ionic-3 and Im hide Tabs bar On Specific pages, Its working fine but i have some issue, some time display this error message

TypeError: Cannot read property 'style' of null

how to fix this issue,

this is my code

check.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams} from 'ionic-angular';


@IonicPage()
@Component({
  selector: 'page-check',
  templateUrl: 'check.html',
})
export class CheckPage {
  tabBarElement: any; // hidetab
  constructor(public navCtrl: NavController, public navParams: NavParams) {
    this.tabBarElement = document.querySelector('.tabbar.show-tabbar');// hidetab

  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad CheckPage');
  }

  ionViewWillEnter() {
    this.tabBarElement.style.display = 'none'; // hidetab
  }

 ionViewWillLeave() {
    this.tabBarElement.style.display = 'flex'; // hidetab
  }
  takeMeBack() {
    this.navCtrl.parent.select(0);  // backbutton
  }
}

Upvotes: 1

Views: 2833

Answers (1)

Mahesh Jadhav
Mahesh Jadhav

Reputation: 1089

Try this maybe it can fix your issue :

ionViewWillEnter() {
let tabBarElement = document.querySelector('.tabbar.show-tabbar');
    if (tabBarElement != null) {
      tabBarElement.style.display = 'none'; // or whichever property which you want to access
    }
}

Upvotes: 3

Related Questions