{"id":720,"date":"2018-02-25T20:33:05","date_gmt":"2018-02-25T12:33:05","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/25\/ionic-%e5%88%9b%e5%bb%ba-app\/"},"modified":"2018-02-25T20:33:05","modified_gmt":"2018-02-25T12:33:05","slug":"ionic-%e5%88%9b%e5%bb%ba-app","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=720","title":{"rendered":"ionic \u521b\u5efa APP"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>ionic \u521b\u5efa APP<\/h1>\n<p>\u524d\u9762\u7684\u7ae0\u8282\u4e2d\u6211\u4eec\u5df2\u7ecf\u5b66\u4f1a\u4e86 ionic \u6846\u67b6\u5982\u4f55\u5bfc\u5165\u5230\u9879\u76ee\u4e2d\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u5982\u4f55\u521b\u5efa\u4e00\u4e2a ionic APP \u5e94\u7528\u3002<\/p>\n<p>ionic \u521b\u5efa APP \u4f7f\u7528 HTML\u3001CSS \u548c Javascript \u6765\u6784\u5efa\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a www \u76ee\u5f55\uff0c\u5e76\u5728\u76ee\u5f55\u4e0b\u521b\u5efa index.html \u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;meta charset=\"utf-8\"&gt;\n    &lt;title&gt;Todo&lt;\/title&gt;\n    &lt;meta name=\"viewport\" content=\"initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width\"&gt;\n\n    &lt;link href=\"lib\/ionic\/css\/ionic.css\" rel=\"stylesheet\"&gt;\n\n    &lt;script src=\"lib\/ionic\/js\/ionic.bundle.js\"&gt;&lt;\/script&gt;\n\n    &lt;!-- \u5728\u4f7f\u7528 Cordova\/PhoneGap \u521b\u5efa\u7684 APP \u4e2d\u5305\u542b\u7684\u6587\u4ef6\uff0c\u7531 Cordova\/PhoneGap \u63d0\u4f9b\uff0c(\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u663e\u793a 404) --&gt;\n    &lt;script src=\"cordova.js\"&gt;&lt;\/script&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>\n\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5f15\u5165\u4e86 Ionic CSS \u6587\u4ef6\u3001 Ionic JS \u6587\u4ef6\u53ca Ionic AngularJS \u6269\u5c55ionic.bundle.js\uff08ionic.bundle.js\uff09\u3002<\/p>\n<p>ionic.bundle.js \u6587\u4ef6\u5df2\u7ecf\u5305\u542b\u4e86 Ionic\u6838\u5fc3JS\u3001AngularJS\u3001Ionic\u7684AngularJS\u6269\u5c55\uff0c\u5982\u679c\u4f60\u9700\u8981\u5f15\u5165\u5176\u4ed6 Angular \u6a21\u5757\uff0c\u53ef\u4ee5\u4ece lib\/js\/angular \u76ee\u5f55\u4e2d\u8c03\u7528\u3002<\/p>\n<p>cordova.js \u662f\u5728\u4f7f\u7528 Cordova\/PhoneGap \u521b\u5efa\u5e94\u7528\u65f6\u751f\u6210\u7684\uff0c\u4e0d\u9700\u8981\u624b\u52a8\u5f15\u5165\uff0c\u4f60\u53ef\u4ee5\u5728 Cordova\/PhoneGap \u9879\u76ee\u4e2d\u627e\u5230\u8be5\u6587\u4ef6\uff0c\u6240\u4ee5\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u663e\u793a 404 \u662f\u6b63\u5e38\u7684\u3002<\/p>\n<hr>\n<h2>\u521b\u5efa APP<\/h2>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u5b9e\u73b0\u4e00\u4e2a\u5305\u542b\u6807\u9898\u3001\u4fa7\u8fb9\u680f\u3001\u5217\u8868\u7b49\u7684\u5e94\u7528,\u8bbe\u8ba1\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2015\/08\/3-mockup.png\"><\/p>\n<h3>\u521b\u5efa\u4fa7\u8fb9\u680f<\/h3>\n<p>\n\u4fa7\u8fb9\u680f\u521b\u5efa\u4f7f\u7528 ion-side-menus \u63a7\u5236\u5668\u3002<\/p>\n<p>\u7f16\u8f91\u6211\u4eec\u5148\u524d\u521b\u5efa\u7684 index.html \u6587\u4ef6\uff0c\u4fee\u6539 &lt;body&gt; \u5185\u7684\u5185\u5bb9\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>\n&lt;body&gt;\n  &lt;ion-side-menus&gt;\n    &lt;ion-side-menu-content&gt;\n    &lt;\/ion-side-menu-content&gt;\n    &lt;ion-side-menu side=\"left\"&gt;\n    &lt;\/ion-side-menu&gt;\n  &lt;\/ion-side-menus&gt;\n&lt;\/body&gt;\n<\/pre>\n<p>\u63a7\u5236\u5668\u89e3\u6790\uff1a<\/p>\n<ul>\n<li><b>ion-side-menus\uff1a<\/b><br \/>\n\u662f\u4e00\u4e2a\u5e26\u6709\u8fb9\u680f\u83dc\u5355\u7684\u5bb9\u5668\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u6309\u94ae\u6216\u8005\u6ed1\u52a8\u5c4f\u5e55\u6765\u5c55\u5f00\u83dc\u5355\u3002<\/li>\n<li><b>ion-side-menu-content<\/b>\uff1a\u5c55\u793a\u4e3b\u8981\u5185\u5bb9\u7684\u5bb9\u5668\uff0c\u53ef\u4ee5\u901a\u8fc7\u6ed1\u52a8\u5c4f\u5e55\u6765\u5c55\u5f00menu\u3002<\/li>\n<li><b>ion-side-menu<\/b>\uff1a\u5b58\u653e\u4fa7\u8fb9\u680f\u7684\u5bb9\u5668\u3002<\/li>\n<\/ul>\n<h3>\u521d\u59cb\u5316 APP<\/h3>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u65b0\u7684  AngularJS \u6a21\u5757\uff0c\u5e76\u521d\u59cb\u5316\uff0c\u4ee3\u7801\u4f4d\u4e8e www\/js\/app.js \u4e2d\uff1a<\/p>\n<pre>\nangular.module('todo', ['ionic'])\n<\/pre>\n<p>\u4e4b\u540e\u5728\u6211\u4eec\u7684 body \u6807\u7b7e\u4e2d\u6dfb\u52a0 ng-app \u5c5e\u6027\uff1a<\/p>\n<pre>\n&lt;body ng-app=\"todo\"&gt;\n<\/pre>\n<p>\u5728 index.html \u6587\u4ef6\u7684 &lt;script src=&#8221;cordova.js&#8221;&gt;&lt;\/script&gt; \u4e0a\u9762\u5f15\u5165 app.js \u6587\u4ef6\uff1a<\/p>\n<pre>\n&lt;script src=\"js\/app.js\"&gt;&lt;\/script&gt;\n<\/pre>\n<p>\u4fee\u6539 index.html \u6587\u4ef6 body \u6807\u7b7e\u7684\u5185\u5bb9\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>\n&lt;body ng-app=\"todo\"&gt;\n  &lt;ion-side-menus&gt;\n\n    &lt;!-- \u4e2d\u5fc3\u5185\u5bb9 --&gt;\n    &lt;ion-side-menu-content&gt;\n      &lt;ion-header-bar class=\"bar-dark\"&gt;\n        &lt;h1 class=\"title\"&gt;Todo&lt;\/h1&gt;\n      &lt;\/ion-header-bar&gt;\n      &lt;ion-content&gt;\n      &lt;\/ion-content&gt;\n    &lt;\/ion-side-menu-content&gt;\n\n    &lt;!-- \u5de6\u4fa7\u83dc\u5355 --&gt;\n    &lt;ion-side-menu side=\"left\"&gt;\n      &lt;ion-header-bar class=\"bar-dark\"&gt;\n        &lt;h1 class=\"title\"&gt;Projects&lt;\/h1&gt;\n      &lt;\/ion-header-bar&gt;\n    &lt;\/ion-side-menu&gt;\n\n  &lt;\/ion-side-menus&gt;\n&lt;\/body&gt;\n<\/pre>\n<p><a href=\"\/try\/tryit.php?filename=ionic_start\" target=\"_blank\" class=\"tryitbtn\">\u5c1d\u8bd5\u4e00\u4e0b \u00bb<\/a><\/p>\n<p>\u4ee5\u4e0a\u6b65\u9aa4\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86 ionic \u57fa\u672c APP \u7684\u5e94\u7528\u3002<\/p>\n<hr>\n<h2>\u521b\u5efa\u5217\u8868<\/h2>\n<p>\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u63a7\u5236\u5668 <b>TodoCtrl<\/b>\uff1a<\/p>\n<pre>\n&lt;body ng-app=\"todo\" ng-controller=\"TodoCtrl\"&gt;\n<\/pre>\n<p>\u5728app.js\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u63a7\u5236\u5668\u5b9a\u4e49\u5217\u8868\u6570\u636e\uff1a<\/p>\n<pre>\nangular.module('todo', ['ionic'])\n\n.controller('TodoCtrl', function($scope) {\n  $scope.tasks = [\n    { title: '\u83dc\u9e1f\u6559\u7a0b' },\n    { title: 'www.runoob.com' },\n    { title: '\u83dc\u9e1f\u6559\u7a0b' },\n    { title: 'www.runoob.com' }\n  ];\n});\n<\/pre>\n<p>\u5728index.html\u9875\u9762\u4e2d\u6570\u636e\u5217\u8868\u6211\u4eec\u4f7f\u7528 Angular ng-repeat \u6765\u8fed\u4ee3\u6570\u636e\uff1a<\/p>\n<pre>\n&lt;!-- \u4e2d\u5fc3\u5185\u5bb9 --&gt;\n&lt;ion-side-menu-content&gt;\n  &lt;ion-header-bar class=\"bar-dark\"&gt;\n    &lt;h1 class=\"title\"&gt;Todo&lt;\/h1&gt;\n  &lt;\/ion-header-bar&gt;\n  &lt;ion-content&gt;\n    &lt;!-- \u5217\u8868 --&gt;\n    &lt;ion-list&gt;\n      &lt;ion-item ng-repeat=\"task in tasks\"&gt;\n        {{task.title}}\n      &lt;\/ion-item&gt;\n    &lt;\/ion-list&gt;\n  &lt;\/ion-content&gt;\n&lt;\/ion-side-menu-content&gt;\n<\/pre>\n<p>\u4fee\u6539\u540e index.html body \u6807\u7b7e\u5185\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\n &lt;body ng-app=\"todo\" ng-controller=\"TodoCtrl\"&gt;\n    &lt;ion-side-menus&gt;\n\n    &lt;!-- \u4e2d\u5fc3\u5185\u5bb9 --&gt;\n    &lt;ion-side-menu-content&gt;\n      &lt;ion-header-bar class=\"bar-dark\"&gt;\n        &lt;h1 class=\"title\"&gt;Todo&lt;\/h1&gt;\n      &lt;\/ion-header-bar&gt;\n      &lt;ion-content&gt;\n        &lt;!-- \u5217\u8868 --&gt;\n        &lt;ion-list&gt;\n          &lt;ion-item ng-repeat=\"task in tasks\"&gt;\n            {{task.title}}\n          &lt;\/ion-item&gt;\n        &lt;\/ion-list&gt;\n      &lt;\/ion-content&gt;\n    &lt;\/ion-side-menu-content&gt;\n\n    &lt;!-- \u5de6\u4fa7\u83dc\u5355 --&gt;\n    &lt;ion-side-menu side=\"left\"&gt;\n      &lt;ion-header-bar class=\"bar-dark\"&gt;\n        &lt;h1 class=\"title\"&gt;Projects&lt;\/h1&gt;\n      &lt;\/ion-header-bar&gt;\n    &lt;\/ion-side-menu&gt;\n\n    &lt;\/ion-side-menus&gt;\n    &lt;script src=\"http:\/\/www.runoob.com\/static\/ionic\/js\/app.js\"&gt;&lt;\/script&gt;\n    &lt;script src=\"cordova.js\"&gt;&lt;\/script&gt;\n&lt;\/body&gt;\n<\/pre>\n<p><a href=\"\/try\/tryit.php?filename=ionic_start2\" target=\"_blank\" class=\"tryitbtn\">\u5c1d\u8bd5\u4e00\u4e0b \u00bb<\/a><\/p>\n<hr>\n<h2>\u521b\u5efa\u6dfb\u52a0\u9875\u9762<\/h2>\n<p>\u4fee\u6539 index.html \u5728 <b>&lt;\/ion-side-menus&gt;<\/b> \u540e\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801:<\/p>\n<pre>\n&lt;script id=\"new-task.html\" type=\"text\/ng-template\"&gt;\n\n  &lt;div class=\"modal\"&gt;\n\n    &lt;!-- Modal header bar --&gt;\n    &lt;ion-header-bar class=\"bar-secondary\"&gt;\n      &lt;h1 class=\"title\"&gt;New Task&lt;\/h1&gt;\n      &lt;button class=\"button button-clear button-positive\" ng-click=\"closeNewTask()\"&gt;Cancel&lt;\/button&gt;\n    &lt;\/ion-header-bar&gt;\n\n    &lt;!-- Modal content area --&gt;\n    &lt;ion-content&gt;\n\n      &lt;form ng-submit=\"createTask(task)\"&gt;\n        &lt;div class=\"list\"&gt;\n          &lt;label class=\"item item-input\"&gt;\n            &lt;input type=\"text\" placeholder=\"What do you need to do?\" ng-model=\"task.title\"&gt;\n          &lt;\/label&gt;\n        &lt;\/div&gt;\n        &lt;div class=\"padding\"&gt;\n          &lt;button type=\"submit\" class=\"button button-block button-positive\"&gt;Create Task&lt;\/button&gt;\n        &lt;\/div&gt;\n      &lt;\/form&gt;\n\n    &lt;\/ion-content&gt;\n\n  &lt;\/div&gt;\n\n&lt;\/script&gt;\n<\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u4e2d\u6211\u4eec\u901a\u8fc7 <b>&lt;script id=&#8221;new-task.html&#8221; type=&#8221;text\/ng-template&#8221;&gt;<\/b> \u5b9a\u4e49\u4e86\u65b0\u7684\u6a21\u677f\u9875\u9762\u3002<\/p>\n<p>\u8868\u5355\u63d0\u4ea4\u65f6\u89e6\u53d1 createTask(task) \u51fd\u6570\u3002 <\/p>\n<p>ng-model=&#8221;task.title&#8221; \u4f1a\u5c06\u8868\u5355\u7684\u8f93\u5165\u6570\u636e\u8d4b\u503c\u7ed9 task \u5bf9\u8c61\u7684 title \u5c5e\u6027\u3002<\/p>\n<p>\u4fee\u6539  <b>&lt;ion-side-menu-content&gt;<\/b> \u5185\u7684\u5185\u5bb9\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\n&lt;!-- \u4e2d\u5fc3\u5185\u5bb9 --&gt;\n&lt;ion-side-menu-content&gt;\n&lt;ion-header-bar class=\"bar-dark\"&gt;\n  &lt;h1 class=\"title\"&gt;Todo&lt;\/h1&gt;\n  &lt;!-- \u65b0\u589e\u6309\u94ae--&gt;\n  &lt;button class=\"button button-icon\" ng-click=\"newTask()\"&gt;\n    &lt;i class=\"icon ion-compose\"&gt;&lt;\/i&gt;\n  &lt;\/button&gt;\n&lt;\/ion-header-bar&gt;\n&lt;ion-content&gt;\n  &lt;!-- \u5217\u8868 --&gt;\n  &lt;ion-list&gt;\n    &lt;ion-item ng-repeat=\"task in tasks\"&gt;\n      {{task.title}}\n    &lt;\/ion-item&gt;\n  &lt;\/ion-list&gt;\n&lt;\/ion-content&gt;\n&lt;\/ion-side-menu-content&gt;\n<\/pre>\n<p>app.js \u6587\u4ef6\u4e2d\uff0c\u63a7\u5236\u5668\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\nangular.module('todo', ['ionic'])\n\n.controller('TodoCtrl', function($scope, $ionicModal) {\n  $scope.tasks = [\n    { title: '\u83dc\u9e1f\u6559\u7a0b' },\n    { title: 'www.runoob.com' },\n    { title: '\u83dc\u9e1f\u6559\u7a0b' },\n    { title: 'www.runoob.com' }\n  ];\n\n  \/\/ \u521b\u5efa\u5e76\u8f7d\u5165\u6a21\u578b\n  $ionicModal.fromTemplateUrl('new-task.html', function(modal) {\n    $scope.taskModal = modal;\n  }, {\n    scope: $scope,\n    animation: 'slide-in-up'\n  });\n\n  \/\/ \u8868\u5355\u63d0\u4ea4\u65f6\u8c03\u7528\n  $scope.createTask = function(task) {\n    $scope.tasks.push({\n      title: task.title\n    });\n    $scope.taskModal.hide();\n    task.title = \"\";\n  };\n\n  \/\/ \u6253\u5f00\u65b0\u589e\u7684\u6a21\u578b\n  $scope.newTask = function() {\n    $scope.taskModal.show();\n  };\n\n  \/\/ \u5173\u95ed\u65b0\u589e\u7684\u6a21\u578b\n  $scope.closeNewTask = function() {\n    $scope.taskModal.hide();\n  };\n});\n<\/pre>\n<hr>\n<h2>\u521b\u5efa\u4fa7\u8fb9\u680f<\/h2>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\u6211\u4eec\u5df2\u7ecf\u5b9e\u73b0\u4e86\u65b0\u589e\u529f\u80fd\uff0c\u73b0\u5728\u6211\u4eec\u4e3a app \u6dfb\u52a0\u4fa7\u8fb9\u680f\u529f\u80fd\u3002<\/p>\n<p>\u4fee\u6539  <b>&lt;ion-side-menu-content&gt;<\/b> \u5185\u7684\u5185\u5bb9\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\n&lt;!-- \u4e2d\u5fc3\u5185\u5bb9 --&gt;\n&lt;ion-side-menu-content&gt;\n  &lt;ion-header-bar class=\"bar-dark\"&gt;\n    &lt;button class=\"button button-icon\" ng-click=\"toggleProjects()\"&gt;\n      &lt;i class=\"icon ion-navicon\"&gt;&lt;\/i&gt;\n    &lt;\/button&gt;\n    &lt;h1 class=\"title\"&gt;{{activeProject.title}}&lt;\/h1&gt;\n    &lt;!-- \u65b0\u589e\u6309\u94ae --&gt;\n    &lt;button class=\"button button-icon\" ng-click=\"newTask()\"&gt;\n      &lt;i class=\"icon ion-compose\"&gt;&lt;\/i&gt;\n    &lt;\/button&gt;\n  &lt;\/ion-header-bar&gt;\n  &lt;ion-content scroll=\"false\"&gt;\n    &lt;ion-list&gt;\n      &lt;ion-item ng-repeat=\"task in activeProject.tasks\"&gt;\n        {{task.title}}\n      &lt;\/ion-item&gt;\n    &lt;\/ion-list&gt;\n  &lt;\/ion-content&gt;\n&lt;\/ion-side-menu-content&gt;\n<\/pre>\n<p>\u6dfb\u52a0\u4fa7\u8fb9\u680f\uff1a<\/p>\n<pre>\n&lt;!-- \u5de6\u8fb9\u680f --&gt;\n&lt;ion-side-menu side=\"left\"&gt;\n&lt;ion-header-bar class=\"bar-dark\"&gt;\n  &lt;h1 class=\"title\"&gt;Projects&lt;\/h1&gt;\n  &lt;button class=\"button button-icon ion-plus\" ng-click=\"newProject()\"&gt;\n  &lt;\/button&gt;\n&lt;\/ion-header-bar&gt;\n&lt;ion-content scroll=\"false\"&gt;\n  &lt;ion-list&gt;\n    &lt;ion-item ng-repeat=\"project in projects\" ng-click=\"selectProject(project, $index)\" ng-class=\"{active: activeProject == project}\"&gt;\n      {{project.title}}\n    &lt;\/ion-item&gt;\n  &lt;\/ion-list&gt;\n&lt;\/ion-content&gt;\n&lt;\/ion-side-menu&gt;\n<\/pre>\n<p> &lt;ion-item&gt; \u4e2d\u7684 ng-class \u6307\u4ee4\u8bbe\u7f6e\u83dc\u5355\u6fc0\u6d3b\u6837\u5f0f\u3002<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u65b0\u7684js \u6587\u4ef6 app2.js(\u4e3a\u4e86\u4e0d\u4e0e\u524d\u9762\u7684\u6df7\u6dc6)\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\nangular.module('todo', ['ionic'])\n\/**\n * The Projects factory handles saving and loading projects\n * from local storage, and also lets us save and load the\n * last active project index.\n *\/\n.factory('Projects', function() {\n  return {\n    all: function() {\n      var projectString = window.localStorage['projects'];\n      if(projectString) {\n        return angular.fromJson(projectString);\n      }\n      return [];\n    },\n    save: function(projects) {\n      window.localStorage['projects'] = angular.toJson(projects);\n    },\n    newProject: function(projectTitle) {\n      \/\/ Add a new project\n      return {\n        title: projectTitle,\n        tasks: []\n      };\n    },\n    getLastActiveIndex: function() {\n      return parseInt(window.localStorage['lastActiveProject']) || 0;\n    },\n    setLastActiveIndex: function(index) {\n      window.localStorage['lastActiveProject'] = index;\n    }\n  }\n})\n\n.controller('TodoCtrl', function($scope, $timeout, $ionicModal, Projects, $ionicSideMenuDelegate) {\n\n  \/\/ A utility function for creating a new project\n  \/\/ with the given projectTitle\n  var createProject = function(projectTitle) {\n    var newProject = Projects.newProject(projectTitle);\n    $scope.projects.push(newProject);\n    Projects.save($scope.projects);\n    $scope.selectProject(newProject, $scope.projects.length-1);\n  }\n\n\n  \/\/ Load or initialize projects\n  $scope.projects = Projects.all();\n\n  \/\/ Grab the last active, or the first project\n  $scope.activeProject = $scope.projects[Projects.getLastActiveIndex()];\n\n  \/\/ Called to create a new project\n  $scope.newProject = function() {\n    var projectTitle = prompt('Project name');\n    if(projectTitle) {\n      createProject(projectTitle);\n    }\n  };\n\n  \/\/ Called to select the given project\n  $scope.selectProject = function(project, index) {\n    $scope.activeProject = project;\n    Projects.setLastActiveIndex(index);\n    $ionicSideMenuDelegate.toggleLeft(false);\n  };\n\n  \/\/ Create our modal\n  $ionicModal.fromTemplateUrl('new-task.html', function(modal) {\n    $scope.taskModal = modal;\n  }, {\n    scope: $scope\n  });\n\n  $scope.createTask = function(task) {\n    if(!$scope.activeProject || !task) {\n      return;\n    }\n    $scope.activeProject.tasks.push({\n      title: task.title\n    });\n    $scope.taskModal.hide();\n\n    \/\/ Inefficient, but save all the projects\n    Projects.save($scope.projects);\n\n    task.title = \"\";\n  };\n\n  $scope.newTask = function() {\n    $scope.taskModal.show();\n  };\n\n  $scope.closeNewTask = function() {\n    $scope.taskModal.hide();\n  }\n\n  $scope.toggleProjects = function() {\n    $ionicSideMenuDelegate.toggleLeft();\n  };\n\n\n  \/\/ Try to create the first project, make sure to defer\n  \/\/ this by using $timeout so everything is initialized\n  \/\/ properly\n  $timeout(function() {\n    if($scope.projects.length == 0) {\n      while(true) {\n        var projectTitle = prompt('Your first project title:');\n        if(projectTitle) {\n          createProject(projectTitle);\n          break;\n        }\n      }\n    }\n  });\n\n});\n<\/pre>\n<p>body \u4e2d ion-side-menus \u4ee3\u7801\u5982\u4e0b\uff1a\uff1a<\/p>\n<pre>\n&lt;ion-side-menus&gt;\n\n&lt;!-- \u4e2d\u5fc3\u5185\u5bb9 --&gt;\n&lt;ion-side-menu-content&gt;\n  &lt;ion-header-bar class=\"bar-dark\"&gt;\n    &lt;button class=\"button button-icon\" ng-click=\"toggleProjects()\"&gt;\n      &lt;i class=\"icon ion-navicon\"&gt;&lt;\/i&gt;\n    &lt;\/button&gt;\n    &lt;h1 class=\"title\"&gt;{{activeProject.title}}&lt;\/h1&gt;\n    &lt;!-- \u65b0\u589e\u6309\u94ae --&gt;\n    &lt;button class=\"button button-icon\" ng-click=\"newTask()\"&gt;\n      &lt;i class=\"icon ion-compose\"&gt;&lt;\/i&gt;\n    &lt;\/button&gt;\n  &lt;\/ion-header-bar&gt;\n  &lt;ion-content scroll=\"false\"&gt;\n    &lt;ion-list&gt;\n      &lt;ion-item ng-repeat=\"task in activeProject.tasks\"&gt;\n        {{task.title}}\n      &lt;\/ion-item&gt;\n    &lt;\/ion-list&gt;\n  &lt;\/ion-content&gt;\n&lt;\/ion-side-menu-content&gt;\n\n&lt;!-- \u5de6\u8fb9\u680f --&gt;\n&lt;ion-side-menu side=\"left\"&gt;\n&lt;ion-header-bar class=\"bar-dark\"&gt;\n  &lt;h1 class=\"title\"&gt;Projects&lt;\/h1&gt;\n  &lt;button class=\"button button-icon ion-plus\" ng-click=\"newProject()\"&gt;\n  &lt;\/button&gt;\n&lt;\/ion-header-bar&gt;\n&lt;ion-content scroll=\"false\"&gt;\n  &lt;ion-list&gt;\n    &lt;ion-item ng-repeat=\"project in projects\" ng-click=\"selectProject(project, $index)\" ng-class=\"{active: activeProject == project}\"&gt;\n      {{project.title}}\n    &lt;\/ion-item&gt;\n  &lt;\/ion-list&gt;\n&lt;\/ion-content&gt;\n&lt;\/ion-side-menu&gt;\n\n&lt;\/ion-side-menus&gt;\n<\/pre>\n<p><a href=\"\/try\/tryit.php?filename=ionic_start4\" target=\"_blank\" class=\"tryitbtn\">\u5c1d\u8bd5\u4e00\u4e0b \u00bb<\/a><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">ionic \u521b\u5efa APP \u524d\u9762\u7684\u7ae0\u8282\u4e2d\u6211\u4eec\u5df2\u7ecf\u5b66\u4f1a\u4e86 ionic \u6846\u67b6\u5982\u4f55\u5bfc\u5165\u5230\u9879\u76ee\u4e2d\u3002 &hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=720\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,26],"tags":[43,72,73,93],"class_list":["post-720","post","type-post","status-publish","format-standard","hentry","category-hybrid","category-mobile","tag-angular","tag-hybrid","tag-ionic","tag-mobile","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=720"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/720\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}