Latest web development tutorials

イオンモーダルウィンドウ

$ 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#のinitializeメソッドにより、オブジェクトを渡します。

戻り値:約束オブジェクト 。約束のオブジェクトは仕様CommonJSワーキンググループでは、非同期プログラミングに統一されたインタフェースを提供することを目指します。


ionicModal

$ ionicModalサービスでインスタンス化。

ヒント:あなたは明確に各モジュールを完了すると、メモリリークを回避するには、remove()メソッドを呼び出してください。

注:「modal.shown 'と、' modal.hiddenは 'パラメータ自体として渡される放送の当初の範囲からモジュール。

ウェイ

initialize(可选)

新しいモーダルウィンドウコントローラの例を作成します。

パラメータ タイプ 詳細
オプション 对象

性質を持っているのいずれかのオプションがオブジェクトをクリックします:

  • {object=} 范围サブクラスが及びます。 デフォルト:$ rootScopeは、サブクラスを作成します。
  • {string=} 动画表示または非表示アニメーションで。 デフォルト:「スライドインアップ」
  • {boolean=} 第一个输入框获取焦点表示されたとき、最初の入力要素に自動的にフォーカスを取得するかどうかをモーダルウィンドウ。 デフォルト:false。
  • {boolean=}背景をクリックbackdropClickToClose`閉じるモーダルウィンドウです。 デフォルト:true。
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();
  };

});