快乐学习 Ionic Framework+PhoneGap 手册1-5 {IO开关}

当然,即使努力了也没做成,至少你也有收获,因为你知道自己以后可以避开这个坑。

这是一个"IO"开关,请看效果图和代码,下一节,说明,数据交换

Index HTML Code

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

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

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app‘s js -->
    <script src="js/app.js"></script>
  </head>
 <body>

    <ion-nav-bar class="bar-positive nav-title-slide-ios7">
      <ion-nav-back-button class="button-icon ion-arrow-left-c">
      </ion-nav-back-button>
    </ion-nav-bar>

    <ion-nav-view animation="slide-left-right"></ion-nav-view>

    <script id="templates/sign-in.html" type="text/ng-template">
      <ion-view title="登录">
        <ion-content>
          <div class="list">
            <label class="item item-input">
              <span class="input-label">用户名</span>
              <input type="text" ng-model="user.username">
            </label>
            <label class="item item-input">
              <span class="input-label">密  码</span>
              <input type="password" ng-model="user.password">
            </label>
          </div>
          <div class="padding">
            <button class="button button-block button-positive" ng-click="signIn(user)">
              立即登录
            </button>
            <p class="text-center">
              <a href="#/forgot-password">找回密码</a>
            </p>
          </div>
        </ion-content>
      </ion-view>
    </script>

    <script id="templates/forgot-password.html" type="text/ng-template">
      <ion-view title="找回密码">
        <ion-content padding="true">
           <p>放弃是经线,坚持是纬线</p>
          <p>没有一个谷底不可逾越</p>
          <p>
            返回 <a href="#/sign-in">登录</a>.
          </p>
        </ion-content>
      </ion-view>
    </script>

    <script id="templates/tabs.html" type="text/ng-template">
      <ion-view>
        <ion-tabs class="tabs-icon-top tabs-positive">

          <ion-tab title="首页" icon="ion-home" href="#/tab/home">
            <ion-nav-view name="home-tab"></ion-nav-view>
          </ion-tab>

          <ion-tab title="关于" icon="ion-ios7-information" href="#/tab/about">
            <ion-nav-view name="about-tab"></ion-nav-view>
          </ion-tab>

          <ion-tab title="退出" icon="ion-log-out" href="#/sign-in">
          </ion-tab>

        </ion-tabs>
      </ion-view>
    </script>

    <script id="templates/home.html" type="text/ng-template">
      <ion-view title="首页">
        <ion-content>

      <div class="list">

        <div class="item item-divider">
          设置
        </div>

        <ion-toggle ng-repeat="item in settingsList"
                    ng-model="item.checked"
                    ng-checked="item.checked">
          {{ item.text }}
        </ion-toggle>

        <div class="item">
          <pre ng-bind="settingsList | json"></pre>
        </div>

        <div class="item item-divider">
          消息通知
        </div>

        <ion-toggle ng-model="pushNotification.checked"
                    ng-change="pushNotificationChange()">
          是否推送消息
        </ion-toggle>

        <div class="item">
          <pre ng-bind="pushNotification | json"></pre>
        </div>

        <ion-toggle toggle-class="toggle-assertive"
                    ng-model="emailNotification"
                    ng-true-value="{夜间模式}"
                    ng-false-value="{正常模式}">
          模式调整
        </ion-toggle>

        <div class="item">
          <pre ng-bind="emailNotification | json"></pre>
        </div>

      </div>

    </ion-content>
      </ion-view>
    </script>

    <script id="templates/facts.html" type="text/ng-template">
      <ion-view title="生活圈">
        <ion-content padding="true">
         <h3>如果你比你身边的绝大多数人都强,那你该换朋友圈了</h3>
          <p>若非青春苦短,谁会想来日方长</p>
       <p>若非青春苦短,谁会想来日方长</p>
          <p>
            <a class="button icon ion-home" href="#/tab/home">首页</a>
            <a class="button icon icon-right ion-chevron-right" href="#/tab/facts2">关于</a>
          </p>
        </ion-content>
      </ion-view>
    </script> 

    <script id="templates/facts2.html" type="text/ng-template">
      <ion-view title="关于">
        <ion-content padding="true">
        <h3>如果你比你身边的绝大多数人都强,那你该换朋友圈了</h3>
          <p>若非青春苦短,谁会想来日方长</p>
       <p>若非青春苦短,谁会想来日方长</p>
            <a class="button icon ion-home" href="#/tab/home"> 首页</a>
            <a class="button icon ion-chevron-left" href="#/tab/facts"> 生活圈</a>
          </p>
        </ion-content>
      </ion-view>
    </script>

    <script id="templates/about.html" type="text/ng-template">
      <ion-view title="关于">
        <ion-content padding="true">
          <h3>如果你比你身边的绝大多数人都强,那你该换朋友圈了</h3>
          <p>若非青春苦短,谁会想来日方长</p>
       <p>若非青春苦短,谁会想来日方长</p>
          <p>
            <a class="button icon icon-right ion-chevron-right" href="#/tab/navstack">关于</a>
          </p>
        </ion-content>
      </ion-view>
    </script>

    <script id="templates/nav-stack.html" type="text/ng-template">
      <ion-view title="其它">
        <ion-content padding="true">
          <p><img src="http://ionicframework.com/img/diagrams/tabs-nav-stack.png" style="width:100%"></p>
        </ion-content>
      </ion-view>
    </script>

  </body>
</html>

App Js Code

angular.module(‘ionicApp‘, [‘ionic‘])

.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state(‘signin‘, {
      url: ‘/sign-in‘,
      templateUrl: ‘templates/sign-in.html‘,
      controller: ‘SignInCtrl‘
    })
    .state(‘forgotpassword‘, {
      url: ‘/forgot-password‘,
      templateUrl: ‘templates/forgot-password.html‘
    })
    .state(‘tabs‘, {
      url: ‘/tab‘,
      abstract: true,
      templateUrl: ‘templates/tabs.html‘
    })
    .state(‘tabs.home‘, {
      url: ‘/home‘,
      views: {
        ‘home-tab‘: {
          templateUrl: ‘templates/home.html‘,
          controller: ‘HomeTabCtrl‘
        }
      }
    })
    .state(‘tabs.facts‘, {
      url: ‘/facts‘,
      views: {
        ‘home-tab‘: {
          templateUrl: ‘templates/facts.html‘
        }
      }
    })
    .state(‘tabs.facts2‘, {
      url: ‘/facts2‘,
      views: {
        ‘home-tab‘: {
          templateUrl: ‘templates/facts2.html‘
        }
      }
    })
    .state(‘tabs.about‘, {
      url: ‘/about‘,
      views: {
        ‘about-tab‘: {
          templateUrl: ‘templates/about.html‘
        }
      }
    })
    .state(‘tabs.navstack‘, {
      url: ‘/navstack‘,
      views: {
        ‘about-tab‘: {
          templateUrl: ‘templates/nav-stack.html‘
        }
      }
    })
    .state(‘tabs.contact‘, {
      url: ‘/contact‘,
      views: {
        ‘contact-tab‘: {
          templateUrl: ‘templates/contact.html‘
        }
      }
    });

   $urlRouterProvider.otherwise(‘/sign-in‘);

})

.controller(‘SignInCtrl‘, function($scope, $state) {

 $scope.settingsList = [
    { text: "Wireless", checked: true },
    { text: "GPS", checked: false },
    { text: "Bluetooth", checked: false }
  ];

  $scope.pushNotificationChange = function() {
    console.log(‘Push Notification Change‘, $scope.pushNotification.checked);
  };

  $scope.pushNotification = { checked: true };
  $scope.emailNotification = ‘Subscribed‘;

  $scope.signIn = function(user) {
    console.log(‘Sign-In‘, user);
    $state.go(‘tabs.home‘);
  };

})

.controller(‘HomeTabCtrl‘, function($scope) {
  console.log(‘HomeTabCtrl‘);
});
时间: 2024-10-07 08:53:27

快乐学习 Ionic Framework+PhoneGap 手册1-5 {IO开关}的相关文章

快乐学习 Ionic Framework+PhoneGap 手册1-3

编程的快乐和乐趣,来自于能成功运行程序并运用到项目中,会在后面案例,实际运用到项目当中与数据更新一起说明 从面板切换开始,请看效果图和代码,这只是一个面板切换的效果 Index HTML Code <!DOCTYPE html> <html ng-app="ionicApp"> <head> <meta charset="utf-8"> <meta name="viewport" conten

快乐学习 Ionic Framework+PhoneGap 手册1-4 {登录页面}

编程的快乐和乐趣,来自于能成功运行程序并运用到项目中 有了面板然后加个登录页面,请看效果图和代码 Index HTML Code <!DOCTYPE html> <html ng-app="ionicApp"> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-s

案例:1 Ionic Framework+AngularJS+ASP.NET MVC WebApi Jsonp 移动开发

落叶的庭院扫的一干二净之后,还要轻轻把树摇一下,抖落几片叶子,这才是Wabi Sabi的境界. 介绍:Ionic是移动框架,angularjs这就不用说了,ASP.Net MVC WebApi提供数据源,开放数据接口 快乐学习 Ionic Framework+PhoneGap 手册1-1{创建APP项目}{点击查看} 快乐学习 Ionic Framework+PhoneGap 手册1-2{介绍Header,Content,Footer的使用}{点击查看} 快乐学习 Ionic Framework

Use SQLite Instead of Local Storage In Ionic Framework【转】

Switching to object-based data storage can often be tough.  If you’re trying to start Phonegap or Ionic Framework development and are coming from native development, the whole local storage concept can be a tough one to grasp.  Or maybe you just pref

Mobile first! Wijmo 5 + Ionic Framework之:费用跟踪 App

?? 费用跟踪应用采用了Wijmo5和Ionic Framework创建,目的是构建一个hybird app. 我们基于<Mobile first! Wijmo 5 + Ionic Framework之:Hello World!>的环境,将在本教程中完成费用跟踪App的构建.下面的代码结构是本教程完成要达到的效果,请预先创建好文件和目录. www/ --> 工程根目录 index.html --> app 布局文件 (主HTML文件) css/ --> css 目录 js/

十分钟使用ionic Framework开发一个跨平台移动应用

Ionic是一个前端的框架,帮助开发者使用HTML5, CSS3和JavaScript做出原生应用.ionic的理念类似前端开发的BootStrap,目标是封装HTML5移动跨平台开发的最佳实践,就像Twitter Bootstrap在前端开发中做的一样.Ionic框架目前发展很迅速,我们从2014年3月开始使用,当时是1.0.0beta2,现在已经更新到1.0.0beta10,大概每2个星期会出一个beta版本,并且都包含实质性更新.Ionic框架很先进,js部分是基于AngularJS框架,

Mobile first! Wijmo 5 + Ionic Framework之:Hello World!

?? 本教程中,我们用Wijmo 5 和 Ionic Framework实现一个Mobile的工程:Hello World. Ionic是什么? Ionic是一个HTML5框架.免费.开源,用于帮助生成hybird mobile Apps (混合移动应用). Ionic包含3部分: CSS 样式:用于渲染Web页面,使得页面更接近原生移动应用 (Native App). AngularJS:Ionic使用AngularJs的扩展指令作为核心框架库,同时AngularJs也加快了开发过程. Apa

Mobile first! Wijmo 5 + Ionic Framework之:Hello Wor

本教程中,我们用Wijmo 5 和 Ionic Framework实现一个Mobile的工程:Hello World. Ionic是什么? Ionic是一个HTML5框架.免费.开源,用于帮助生成hybird mobile Apps (混合移动应用). Ionic包含3部分: CSS 样式:用于渲染Web页面,使得页面更接近原生移动应用 (Native App). AngularJS:Ionic使用AngularJs的扩展指令作为核心框架库,同时AngularJs也加快了开发过程. Apache

【Ionic】---Using Local Notifications In Your Ionic Framework App

Using Local Notifications In Your Ionic Framework App 配置好ng-cordova先 <script src="lib/ngCordova/dist/ng-cordova.js"></script> <script src="cordova.js"></script> var ionicApp = angular.module("ionic", [