Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    
    <title>Todo</title>

    <link href="https://code.ionicframework.com/1.0.0-beta.1/css/ionic.min.css" rel="stylesheet">
    <script src="https://code.ionicframework.com/1.0.0-beta.1/js/ionic.bundle.min.js"></script>
  </head>
<body ng-app="todo" ng-controller="TodoCtrl">
        <ion-side-menus>
           <ion-side-menu-content>
                <ion-header-bar class="bar-dark">
                    <button class="button button-icon" ng-click="toggleProjects()">
                        <i class="icon ion-navicon"></i>
                    </button>
                    <h1 class="title">{{activeProject.title}}</h1>
                <!-- New Task button-->
                    <button class="button button-icon" ng-click="newTask()">
                        <i class="icon ion-compose"></i>
                    </button>
                </ion-header-bar>
                <ion-content scroll="true">
                    <ion-list>
                        <ion-item ng-repeat="task in activeProject.tasks">
                            {{task.title}}
                        </ion-item>
                    </ion-list>
                </ion-content>
            </ion-side-menu-content>
            
            <ion-side-menu side="left">
                <ion-header-bar class="bar-dark">
                    <h1 class="title">Projects</h1>
                    <button class="button button-icon ion-plus" ng-click="showProjectModal()">
                    </button>
                </ion-header-bar>
                <ion-content scroll="true">
                    <ion-list>
                        <ion-item ng-repeat="project in projects" ng-click="selectProject(project, $index)" ng-class="{active: activeProject == project}">
                            {{project.title}}
                        </ion-item>
                    </ion-list>
                </ion-content>
            </ion-side-menu>
            <script id="new-task.html" type="text/ng-template">

              <div class="modal">

                <!-- Modal header bar -->
                <ion-header-bar class="bar-secondary">
                  <h1 class="title">New Task</h1>
                  <button class="button button-clear button-positive" ng-click="closeNewTask()">Cancel</button>
                </ion-header-bar>

                <!-- Modal content area -->
                <ion-content>

                  <form ng-submit="createTask(task)">
                    <div class="list">
                      <label class="item item-input">
                        <input type="text" placeholder="What do you need to do?" ng-model="task.title">
                      </label>
                    </div>
                    <div class="padding">
                      <button type="submit" class="button button-block button-positive">Create Task</button>
                    </div>
                  </form>

                </ion-content>

              </div>

            </script>
            <script id="new-project.html" type="text/ng-template">

              <div class="modal">

                <!-- Modal header bar -->
                <ion-header-bar class="bar-secondary">
                  <h1 class="title">New Project</h1>
                  <button class="button button-clear button-positive" ng-click="closeNewProject()">Cancel</button>
                </ion-header-bar>

                <!-- Modal content area -->
                <ion-content>

                  <form ng-submit="newProject(project)">
                    <div class="list">
                      <label class="item item-input">
                        <input type="text" placeholder="Project Name" ng-model="project.title">
                      </label>
                    </div>
                    <div class="padding">
                      <button type="submit" class="button button-block button-positive">Create Project</button>
                    </div>
                  </form>

                </ion-content>

              </div>

            </script>
        </ion-side-menus>
    </body>
              
            
!

CSS

              
                
              
            
!

JS

              
                angular.module('todo', ['ionic'])

.factory('Projects', function() {
  return {
    all: function() {
      var projectString = window.localStorage['projects'];
      if(projectString) {
        return angular.fromJson(projectString);
      }
      return [];
    },
    save: function(projects) {
      window.localStorage['projects'] = angular.toJson(projects);
    },
    newProject: function(projectTitle) {
      // Add a new project
      return {
        title: projectTitle,
        tasks: []
      };
    },
    getLastActiveIndex: function() {
      return parseInt(window.localStorage['lastActiveProject']) || 0;
    },
    setLastActiveIndex: function(index) {
      window.localStorage['lastActiveProject'] = index;
    }
  }
})

.controller('TodoCtrl', function($scope, $timeout, $ionicModal, $ionicSideMenuDelegate, Projects) {

  // A utility function for creating a new project
  // with the given projectTitle
  var createProject = function(projectTitle) {
    var newProject = Projects.newProject(projectTitle);
    $scope.projects.push(newProject);
    Projects.save($scope.projects);
    $scope.selectProject(newProject, $scope.projects.length-1);
    $scope.projectModal.hide();
  }


  // Load or initialize projects
  $scope.projects = Projects.all();

  // Grab the last active, or the first project
  $scope.activeProject = $scope.projects[Projects.getLastActiveIndex()];
    
    $scope.showProjectModal = function(){
        $scope.projectModal.show();
    };
    
  // Called to create a new project
  $scope.newProject = function(project) {
    //var projectTitle = prompt('Project name');
    var projectTitle = project.title;
    if(projectTitle) {
      createProject(projectTitle);
    }
  };

  // Called to select the given project
  $scope.selectProject = function(project, index) {
    $scope.activeProject = project;
    Projects.setLastActiveIndex(index);
   // $scope.sideMenuController.close();
   $ionicSideMenuDelegate.toggleRight();
  };

  // Create our modal
  $ionicModal.fromTemplateUrl('new-task.html', function(modal) {
    $scope.taskModal = modal;
  }, {
    scope: $scope
  });
  $ionicModal.fromTemplateUrl('new-project.html', function(modal) {
    $scope.projectModal = modal;
  }, {
    scope: $scope
  });

  $scope.createTask = function(task) {
    if(!$scope.activeProject || !task) {
      return;
    }
    $scope.activeProject.tasks.push({
      title: task.title
    });
    $scope.taskModal.hide();

    // Inefficient, but save all the projects
    Projects.save($scope.projects);

    task.title = "";
  };

    $scope.newTask = function() {
        $scope.taskModal.show();
    };

    $scope.closeNewTask = function() {
        $scope.taskModal.hide();
    }
    
    $scope.closeNewProject = function(){
        $scope.projectModal.hide();
    }
    
    $scope.toggleProjects = function() {
        //console.log("---------------------------");
        //console.log($scope);
        //$scope.sideMenuController.toggleLeft();
        $ionicSideMenuDelegate.toggleLeft();
    };


  // Try to create the first project, make sure to defer
  // this by using $timeout so everything is initialized
  // properly
  $timeout(function() {
    if($scope.projects.length == 0) {
      //while(true) {
        $scope.projectModal.show();
        //var projectTitle = prompt('Your first project title:');
        //if(projectTitle) {
          //createProject(projectTitle);
          //break;
        //}
      //}
    }
  });

});
              
            
!
999px

Console