javascript - How to easily make ionic tabs navigation - Stack Overflow

As I recently started working with "ionic", I am facing a problem making a "tabs navigat

As I recently started working with "ionic", I am facing a problem making a "tabs navigation".

I was following a simple tutorial, I made a navigation with two tabs, but I couldn't make three tabs, it doesn't work properly, I'm afraid I didn't understand the concept of these tabs.

CODEPEN CODE + DEMO

Here is my awesome code :

<ion-tabs class="tabs-striped tabs-top tabs-background-dark tabs-color-energized">

        <ion-tab title="help"ui-sref="help">
           <ion-nav-view name="help"></ion-nav-view>
        </ion-tab>

        <ion-tab title="home" ui-sref="home">
            <ion-nav-view name="home"></ion-nav-view> 
        </ion-tab>

     <ion-tab title="contact" ui-sref="contact">
            <ion-nav-view name="contact"></ion-nav-view> 
        </ion-tab>



    </ion-tabs> 
 <script type="text/ng-template" id="home.html">
  <ion-view title="Home">
    <ion-content padding="true">
      <h2>Home Page</h2>
      <p>Here's the main route for the app.</p>
    </ion-content>
  </ion-view>
</script>

<script type="text/ng-template" id="help.html">
  <ion-view title="Help">
    <ion-content padding="true">
       <h2>Using the app</h2>
       <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis architecto hic officia quasi excepturi sequi deleniti maiores consectetur veritatis sint?</p>
    </ion-content>
  </ion-view>
</script>

      <script type="text/ng-template" id="contact.html">
  <ion-view title="Contact">
    <ion-content padding="true">
       <h2>Using the app</h2>
       <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis architecto hic officia quasi excepturi sequi deleniti maiores consectetur veritatis sint?</p>
    </ion-content>
  </ion-view>
</script>

app.js :

.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/')

$stateProvider
    .state('home', {
  url: '/home',
  views: {
    home: {
      templateUrl: 'home.html'
    }
  }
})

 .state('help', {
  url: '/help',
  views: {
    help: {
      templateUrl: 'help.html'
    }
  }
})

.state('contact', {
  url: '/contact',
  views: {
    help: {
      templateUrl: 'contact.html'
    }
  }
})


})

As I recently started working with "ionic", I am facing a problem making a "tabs navigation".

I was following a simple tutorial, I made a navigation with two tabs, but I couldn't make three tabs, it doesn't work properly, I'm afraid I didn't understand the concept of these tabs.

CODEPEN CODE + DEMO

Here is my awesome code :

<ion-tabs class="tabs-striped tabs-top tabs-background-dark tabs-color-energized">

        <ion-tab title="help"ui-sref="help">
           <ion-nav-view name="help"></ion-nav-view>
        </ion-tab>

        <ion-tab title="home" ui-sref="home">
            <ion-nav-view name="home"></ion-nav-view> 
        </ion-tab>

     <ion-tab title="contact" ui-sref="contact">
            <ion-nav-view name="contact"></ion-nav-view> 
        </ion-tab>



    </ion-tabs> 
 <script type="text/ng-template" id="home.html">
  <ion-view title="Home">
    <ion-content padding="true">
      <h2>Home Page</h2>
      <p>Here's the main route for the app.</p>
    </ion-content>
  </ion-view>
</script>

<script type="text/ng-template" id="help.html">
  <ion-view title="Help">
    <ion-content padding="true">
       <h2>Using the app</h2>
       <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis architecto hic officia quasi excepturi sequi deleniti maiores consectetur veritatis sint?</p>
    </ion-content>
  </ion-view>
</script>

      <script type="text/ng-template" id="contact.html">
  <ion-view title="Contact">
    <ion-content padding="true">
       <h2>Using the app</h2>
       <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis architecto hic officia quasi excepturi sequi deleniti maiores consectetur veritatis sint?</p>
    </ion-content>
  </ion-view>
</script>

app.js :

.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/')

$stateProvider
    .state('home', {
  url: '/home',
  views: {
    home: {
      templateUrl: 'home.html'
    }
  }
})

 .state('help', {
  url: '/help',
  views: {
    help: {
      templateUrl: 'help.html'
    }
  }
})

.state('contact', {
  url: '/contact',
  views: {
    help: {
      templateUrl: 'contact.html'
    }
  }
})


})

http://codepen.io/stranger90/pen/MwjGPY

Share Improve this question edited May 22, 2015 at 8:07 Deenadhayalan Manoharan 5,44414 gold badges32 silver badges50 bronze badges asked May 22, 2015 at 8:03 Yasser B.Yasser B. 8357 gold badges21 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

In your views at your contact state you still have help as a view:

.state('contact', {
    url: '/contact',
        views: {
            help: { // <-- Change this to 'contact'
                templateUrl: 'contact.html'
            }
        }
})

Codepen

I will try to explain you how that work.

So in your app.js file you have the configuration of routing. This routing will allow you to associate a state at an url and a template (file.html). ref: Ui-router

In your html page : This directive ui-sref="help" will call the state "help" and display a page (templateUrl). In this case this will display the content of help.html

    <ion-tab title="help"ui-sref="help">
       <ion-nav-view name="help"></ion-nav-view>
    </ion-tab>

In this exemple every html pages are in the main html page : Exemple : this is the help.html page

    <script type="text/ng-template" id="help.html">
       <ion-view title="Help">
         <ion-content padding="true">
          <h2>Using the app</h2>
              <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis architecto hic officia quasi excepturi sequi deleniti maiores consectetur veritatis sint?</p>
            </ion-content>
       </ion-view>
     </script>

There you have one mistake :

 .state('contact', {
  url: '/contact',
   views: {
      contact: { // here it's not help but contact
       templateUrl: 'contact.html'
     }
    }
 })

I hope this help you, sorry if my english is not correct. This tutorial can help you : Ionic routing tutorial

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745239558a4618096.html

相关推荐

  • javascript - How to easily make ionic tabs navigation - Stack Overflow

    As I recently started working with "ionic", I am facing a problem making a "tabs navigat

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信