<!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.controller('myCtrl01', function($scope, $ionicModal) { $scope.datas = [ { name: 'Gordon Freeman',age:18 }, { name: 'Barney Calhoun',age:20 }, { name: 'Lamarr the Headcrab',age:16} ]; $ionicModal.fromTemplateUrl("templates/modal.html",function (modal) { $scope.modal = modal; },{ scope: $scope, animation: 'slide-in-up' }); $scope.showModal=function () { $scope.modal.show(); } $scope.upLoadData=function (newData) { if (newData.name&&newData.age){ $scope.datas.push({name:newData.name,age:newData.age}); $scope.modal.hide(); } newData.name=''; newData.age=''; } }); </script> </head> <body ng-app="myApp" ng-controller="myCtrl01"> <ion-header-bar class="bar-positive"> <button class="button button-icon"> <i class="icon ion-navicon-round"></i> </button> <h1 class="title">ionic 模态窗口</h1> <button class="button button-icon" ng-click="showModal()"> <i class="icon ion-compose"></i> </button> </ion-header-bar> <ion-content> <ion-list> <ion-item ng-repeat="x in datas">{{x.name}} {{x.age}}</ion-item> </ion-list> </ion-content> <script id="templates/modal.html" type="text/ng-template"> <ion-modal-view> <ion-header-bar class="bar-positive"> <h1 class="title">这是新的Task</h1> <button class="button button-icon" ng-click="modal.hide()">取消</button> </ion-header-bar> <ion-content class="padding"> <div class="list"> <label class="item item-input"> <span class="input-label">您的姓名</span> <input type="text" placeholder="请输入您的姓名"ng-model="newData.name"> </label> <label class="item item-input"> <span class="input-label">您的年龄</span> <input type="text" placeholder="请输入您的年龄" ng-model="newData.age"> </label> <button class="button button-block button-positive" ng-click="upLoadData(newData)">提交</button> </div> </ion-content> </ion-modal-view> </script> </body> </html>