หน้าต่างกิริยาไอออนิก
$ IonicModal
$ IonicModal สามารถครอบคลุมเนื้อหาหลักของอินเตอร์เฟซผู้ใช้กล่อง
คุณสามารถฝังรหัสต่อไปนี้ (ภายในรหัสตามสถานการณ์ทางธุรกิจของคุณเองเปลี่ยนแปลงที่สอดคล้องกัน) ในแฟ้มดัชนีของคุณหรือไฟล์อื่น ๆ
<script id="my-modal.html" type="text/ng-template"> <ion-modal-view> <ion-header-bar> <h1 class="title">My Modal title</h1> </ion-header-bar> <ion-content> Hello! </ion-content> </ion-modal-view> </script>
จากนั้นคุณสามารถในการควบคุมของคุณภายในฉีด $ ionicModal แล้วโทรหาคุณเพียงแค่เขียนแม่แบบเริ่มต้น ในรหัสต่อไปนี้:
angular.module('testApp', ['ionic']) .controller('MyController', function($scope, $ionicModal) { $ionicModal.fromTemplateUrl('my-modal.html', { scope: $scope, animation: 'slide-in-up' }).then(function(modal) { $scope.modal = modal; }); $scope.openModal = function() { $scope.modal.show(); }; $scope.closeModal = function() { $scope.modal.hide(); }; //Cleanup the modal when we're done with it! $scope.$on('$destroy', function() { $scope.modal.remove(); }); // Execute action on hide modal $scope.$on('modal.hidden', function() { // Execute action }); // Execute action on remove modal $scope.$on('modal.removed', function() { // Execute action }); });
ทาง
fromTemplate(templateString, options)
พารามิเตอร์ | ชนิด | รายละเอียด |
---|---|---|
templateString | 字符串 | แม่แบบ String เป็นหน้าต่างเนื้อหากิริยา |
ตัวเลือก | 对象 | ตัวเลือกการส่งผ่านไปยัง ionicModal # เริ่มต้นวิธีการ |
ผลตอบแทน: วัตถุตัวอย่างของการควบคุม ionicModal
fromTemplateUrl(templateUrl, options)
พารามิเตอร์ | ชนิด | รายละเอียด |
---|---|---|
templateUrl | 字符串 | กำลังโหลดเทมเพลต URL |
ตัวเลือก | 对象 | ผ่านวัตถุโดยวิธี ionicModal # เริ่มต้น |
ผลตอบแทน: วัตถุสัญญาวัตถุสัญญาเป็นข้อกำหนด CommonJS คณะทำงานก็มีจุดมุ่งหมายเพื่อให้อินเตอร์เฟซการเขียนโปรแกรมแบบครบวงจรเพื่อไม่ตรงกัน
ionicModal
บริการ $ ionicModal อินสแตนซ์
เคล็ดลับ: เมื่อคุณเสร็จสิ้นแต่ละโมดูลที่ชัดเจนให้แน่ใจว่าจะเรียกลบ () วิธีการที่จะหลีกเลี่ยงการรั่วไหลของหน่วยความจำ
หมายเหตุ: โมดูลจากช่วงเริ่มต้นของการออกอากาศ 'modal.shown' และ 'modal.hidden' ที่จะส่งผ่านเป็นพารามิเตอร์ตัวเอง
ทาง
initialize(可选)
สร้างกิริยาเช่นควบคุมหน้าต่างใหม่
พารามิเตอร์ | ชนิด | รายละเอียด |
---|---|---|
ตัวเลือก | 对象 | คลิกที่หนึ่งในตัวเลือกวัตถุที่มีคุณสมบัติ:
|
show()
เช่นหน้าต่างกิริยา
- กลับค่า:
promise
วัตถุสัญญาหลังจากเสร็จสิ้นการเคลื่อนไหวได้รับการแก้ไขในหน้าต่างกิริยา
hide()
ซ่อนหน้าต่างกิริยา
- กลับค่า:
promise
วัตถุสัญญาหลังจากเสร็จสิ้นการเคลื่อนไหวได้รับการแก้ไขในหน้าต่างกิริยา
remove()
ลบเช่นหน้าต่างกิริยาจาก DOM และทำความสะอาด
- กลับค่า:
promise
วัตถุสัญญาหลังจากเสร็จสิ้นการเคลื่อนไหวได้รับการแก้ไขในหน้าต่างกิริยา
isShown()
- ผลตอบแทน: ค่าบูลีนใช้ในการกำหนดหน้าต่างกิริยาจะปรากฏ
ตัวอย่าง
โค้ด 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>本教程(w3big.com)</title> <link href="http://www.w3big.com/static/ionic/css/ionic.min.css" rel="stylesheet"> <script src="http://www.w3big.com/static/ionic/js/ionic.bundle.min.js"></script> </head> <body ng-controller="AppCtrl"> <ion-header-bar class="bar-positive"> <h1 class="title">Contacts</h1> <div class="buttons"> <button class="button button-icon ion-compose" ng-click="modal.show()"> </button> </div> </ion-header-bar> <ion-content> <ion-list> <ion-item ng-repeat="contact in contacts"> {{contact.name}} </ion-item> </ion-list> </ion-content> <script id="templates/modal.html" type="text/ng-template"> <ion-modal-view> <ion-header-bar class="bar bar-header bar-positive"> <h1 class="title">New Contact</h1> <button class="button button-clear button-primary" ng-click="modal.hide()">Cancel</button> </ion-header-bar> <ion-content class="padding"> <div class="list"> <label class="item item-input"> <span class="input-label">First Name</span> <input ng-model="newUser.firstName" type="text"> </label> <label class="item item-input"> <span class="input-label">Last Name</span> <input ng-model="newUser.lastName" type="text"> </label> <label class="item item-input"> <span class="input-label">Email</span> <input ng-model="newUser.email" type="text"> </label> <button class="button button-full button-positive" ng-click="createContact(newUser)">Create</button> </div> </ion-content> </ion-modal-view> </script> </body> </html>
โค้ด CSS
body { cursor: url('../try/demo_source/finger.png'), auto; }
โค้ด JavaScript
angular.module('ionicApp', ['ionic']) .controller('AppCtrl', function($scope, $ionicModal) { $scope.contacts = [ { name: 'Gordon Freeman' }, { name: 'Barney Calhoun' }, { name: 'Lamarr the Headcrab' }, ]; $ionicModal.fromTemplateUrl('templates/modal.html', { scope: $scope }).then(function(modal) { $scope.modal = modal; }); $scope.createContact = function(u) { $scope.contacts.push({ name: u.firstName + ' ' + u.lastName }); $scope.modal.hide(); }; });