Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabs in ionic is not showing content

I am trying to show content. I added custom code here manually on custom template file.

  <ion-content>


<ion-tabs class="tabs-positive tabs-icon-only">

  <ion-tab title="Home" icon-on="ion-ios-filing" icon-off="ion-ios-filing-outline">
    My Content here 
  </ion-tab>

  <ion-tab title="About" icon-on="ion-ios-clock" icon-off="ion-ios-clock-outline">
     My Content here 1
  </ion-tab>

  <ion-tab title="Settings" icon-on="ion-ios-gear" icon-off="ion-ios-gear-outline">
    My Content here 3
  </ion-tab>

</ion-tabs>
  </ion-content>
</ion-view>

I took example code from here

http://ionicframework.com/docs/api/directive/ionTabs/

I am able to see tabs, but not content. And yes if i follow sample app tab for ionic i am able to do this. But i need above one.

Can we show content here.

like image 520
Hitu Bansal Avatar asked Aug 07 '15 10:08

Hitu Bansal


People also ask

How do you use ionic tabs?

We can access the Ionic tabs by using the standard <ion-tabs> component. This component works as a router outlet to handle navigation. It does not provide any mechanism to switch between tabs. If you need to do switch between tabs, use <ion-tab-bar> as a direct child element of <ion-tabs>.

How do you get a selected tab in ionic?

Selecting a Tab There are different ways you can select a specific tab from the tabs component. You can use the selectedIndex property to set the index on the <ion-tabs> element, or you can call select() from the Tabs instance after creation.

How do you hide tabs in ionic?

There is a simple way to implement that - moving the route you wish to hide the tab-bar to the tabs module, outside of tabs children routes. Moving this route to tabs routing module will hide tab-bar from the page.


1 Answers

You have to use a view to load content within the tabs directive. The route state uses the name of the view to place the content that will reside within the tab.

// Notice the referenced view is "home-tab"
.state('tabs.home', {
  url: "/home",
  views: {
    'home-tab': {
      templateUrl: "templates/home.html",
      controller: 'HomeTabCtrl'
    }
  }
})

// Which correlates to the name of the view, which is also "home-tab"
<ion-tab title="Home" icon="ion-home" href="#/tab/home">
  <ion-nav-view name="home-tab"></ion-nav-view>
</ion-tab>

You can add it easily within the same file (like in the example) using a template, which correlates using the templateUrl of the route to the id of the template in the markup:

<script id="templates/home.html" type="text/ng-template">
  <ion-view view-title="Home">
    <ion-content class="padding">
      <p>
        // Your content
      </p>
    </ion-content>
  </ion-view>
</script>

For a bit more information on setting up tabs in ionic there's also this post.

like image 135
mtpultz Avatar answered Oct 11 '22 09:10

mtpultz