快乐学习 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'); });