ionic js 模型 $ionicModal 可以遮住用户主界面的内容(2)

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(); }; });

完整源码:

<html ng-app="ionicApp"> <head> <meta charset="utf-8"> <meta content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title></title> <link href="https://cdn.bootcss.com/ionic/1.0.1/css/ionic.min.css"> <script src="https://cdn.bootcss.com/ionic/1.0.1/js/ionic.bundle.min.js"></script> <style> body { cursor: url('http://ionicframework.com/img/finger.png'), auto; } </style> <script> 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(); }; }); </script> </head> <body ng-controller="AppCtrl"> <ion-header-bar> <h1>Contacts</h1> <div> <button 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 type="text/ng-template"> <ion-modal-view> <ion-header-bar> <h1>New Contact</h1> <button ng-click="modal.hide()">Cancel</button> </ion-header-bar> <ion-content> <div> <label> <span>First Name</span> <input ng-model="newUser.firstName" type="text"> </label> <label> <span>Last Name</span> <input ng-model="newUser.lastName" type="text"> </label> <label> <span>Email</span> <input ng-model="newUser.email" type="text"> </label> <button ng-click="createContact(newUser)">Create</button> </div> </ion-content> </ion-modal-view> </script> </body> </html>

ionic js 模型 $ionicModal 可以遮住用户主界面的内容

ionic js 模型 $ionicModal 可以遮住用户主界面的内容

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzpyys.html