이온 모달 창
$ 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 | 字符串 | 콘텐츠 모달 창으로 문자열 템플릿입니다. |
옵션 | 对象 | 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; }
자바 스크립트 코드
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(); }; });