【2016.09.07】【ionic 导航和路由的使用】

170214_4I1O_2650892.png

170230_bfuu_2650892.png

170244_wjHJ_2650892.png

170313_vLLT_2650892.png

 

一、index页面

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Todo</title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

  <link href="lib/ionic/css/ionic.css" rel="stylesheet">

  <script src="lib/ionic/js/ionic.bundle.js"></script>
  <script src="js/app.js"></script>

  <!-- 在使用 Cordova/PhoneGap 创建的 APP 中包含的文件,由 Cordova/PhoneGap 提供,(开发过程中显示 404) -->
  <script src="cordova.js"></script>
  <script>
    var app = angular.module("myApp",["ionic"]);
    app.run(function($ionicPlatform) {
        $ionicPlatform.ready(function() {
          // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
          // for form inputs)
          if(window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
          }
          if(window.StatusBar) {
            StatusBar.styleDefault();
          }
        });
      });

    app.config(function($stateProvider, $urlRouterProvider) {
      $stateProvider
        .state('tab', {
          url: '/tab',
          abstract: true,
          templateUrl: 'templates/tabs.html'
        })
        .state('tab.home',{
          url: '/home',
          views: {
            'tab-home': {
              templateUrl: 'templates/tab-home.html',
              controller: 'homeCtrl'
            }
          }
        })
        .state('tab.homesonpage',{
          url: '/homesonpage',
          views: {
            'tab-home': {
              templateUrl: 'templates/home-sonpage.html',
            }
          }
        })
        .state('tab.homesonsonpage',{
          url: '/homesonsonpage',
          views: {
            'tab-home': {
              templateUrl: 'templates/home-son-sonpage.html',
            }
          }
        })
        .state('tab.collect',{
          url: '/collect',
          views: {
            'collect-tab': {
              templateUrl: 'templates/tab-collect.html',
              controller: 'homeCtrl'
            }
          }
        })
        .state('tab.settings',{
          url: '/settings',
          views: {
            'settings-tab': {
              templateUrl: 'templates/tab-settings.html',
              controller: 'homeCtrl'
            }
          }
        });

      $urlRouterProvider.otherwise('/tab/home');
    });

    app.controller('myCtrl01', function($scope,$ionicHistory) {
      $scope.name = "宋玉清";
      $scope.getPreviousTitle = function() {
        return $ionicHistory.backTitle();
      };
    });

    app.controller('homeCtrl', function($scope) {
      $scope.name = "朱明宇";
    });

  </script>

</head>
<body ng-app="myApp" ng-controller="myCtrl01">
  <ion-nav-bar class="bar-positive">
    <ion-nav-back-button class="button-clear">
      <i class="icon ion-arrow-left-c"></i>
    </ion-nav-back-button>
  </ion-nav-bar>
  <ion-nav-view></ion-nav-view>
</body>
</html>

二、下方Tabs页面

<ion-tabs class="tabs-icon-top tabs-stable">

  <ion-tab class="tab-item-assertive" title="主页" icon="ion-home" href="#/tab/home">
    <ion-nav-view name="tab-home"></ion-nav-view>
  </ion-tab>

  <ion-tab class="tab-item-assertive" title="收藏" icon="ion-star" href="#/tab/collect">
    <ion-nav-view name="collect-tab"></ion-nav-view>
  </ion-tab>

  <ion-tab class="tab-item-assertive" title="设置" icon="ion-gear-a" href="#/tab/settings">
    <ion-nav-view name="settings-tab"></ion-nav-view>
  </ion-tab>

</ion-tabs>

三、首页的展示

<ion-view view-title="这是主页">
  <ion-nav-buttons side="right">
    <button class="button" ng-click="doSomething()">
      我是右侧按钮
    </button>
  </ion-nav-buttons>
  <ion-content class="padding">
    <h2>Welcome to Ionic</h2>
    <p>
      This is the Ionic starter for tabs-based apps. For other starters and ready-made templates, check out the <a href="http://market.ionic.io/starters" target="_blank">Ionic Market</a>.
    </p>
    <p>
      To edit the content of each tab, edit the corresponding template file in <code>www/templates/</code>. This template is <code>www/templates/tab-dash.html</code>
    </p>
    <p>
      If you need help with your app, join the Ionic Community on the <a href="http://forum.ionicframework.com" target="_blank">Ionic Forum</a>. Make sure to <a href="http://twitter.com/ionicframework" target="_blank">follow us</a> on Twitter to get important updates and announcements for Ionic developers.
    </p>
    <p>
      For help sending push notifications, join the <a href="https://apps.ionic.io/signup" target="_blank">Ionic Platform</a> and check out <a href="http://docs.ionic.io/docs/push-overview" target="_blank">Ionic Push</a>. We also have other services available.
    </p>
    <p>{{name}}</p>
    <a href="#/tab/homesonpage" class="button button-positive">点击进入子页面</a>
  </ion-content>
</ion-view>

转载于:https://my.oschina.net/YongfengHe/blog/743787

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值