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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <html>

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

  <title></title>

  <link href="https://code.ionicframework.com/1.0.0-rc.5/css/ionic.min.css" rel="stylesheet">
  <script src="https://code.ionicframework.com/1.0.0-rc.5/js/ionic.bundle.min.js"></script>
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pouchdb/3.4.0/pouchdb.min.js"></script>
</head>

<body ng-app="starter">

   <ion-pane ng-controller="TodoController">
     <ion-header-bar class="bar-stable">
       <div class="buttons">
        <button class="button button-icon icon ion-ios-minus-outline"
          ng-click="showDelete = !showDelete"></button>
       </div>
       <h1 class="title">ToDo</h1>
       <button class="right button button-icon icon ion-plus" ng-click="create()"></button>
     </ion-header-bar>
     <ion-content>
       <ion-list show-delete="showDelete">
         <ion-item ng-repeat="todo in todos | orderBy:'done'">
           <ion-checkbox ng-model="todo.done" ng-change="update(todo)">{{todo.title}}</ion-checkbox>
            <ion-delete-button class="ion-minus-circled" ng-click="todos.splice($index, 1)">
            </ion-delete-button>

         </ion-item>
       </ion-list>
     </ion-content>
   </ion-pane>

</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                // Ionic Starter App
var localDB = new PouchDB("todos");
var remoteDB = new PouchDB("http://128.199.48.178:5984/todos");

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var app = angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  localDB.sync(remoteDB, {
    live: true
  });
});

app.factory('PouchDBListener', ['$rootScope', function($rootScope) {
  localDB.changes({
    continuous: true,
    onChange: function(change) {
      if (!change.deleted) {
        $rootScope.$apply(function() {
          localDB.get(change.id, function(err, doc) {
            $rootScope.$apply(function() {
              if (err) console.log(err);
              $rootScope.$broadcast('add', doc);
            })
          });
        })
      } else {
        $rootScope.$apply(function() {
          $rootScope.$broadcast('delete', change.id);
        });
      }
    }
  });
  return true;
}]);

app.controller("TodoController", function($scope, $ionicPopup, PouchDBListener) {
  $scope.todos = [];
  $scope.showDelete = false;
  $scope.create = function() {
    $ionicPopup.prompt({
        title: 'Enter a new TODO',
        inputType: 'text'
      })
      .then(function(result) {
        if (result) {
          if ($scope.hasOwnProperty("todos") !== true) {
            $scope.todos = [];
          }
          localDB.post({
            title: result,
            done: false
          });
        } else {
          console.log("Action cancelled.");
        }
      });
  }

  $scope.update = function(todo) {
    localDB.put({
        _id: todo._id,
        _rev: todo._rev,
        title: todo.title,
        done: todo.done
      })
      .then(function(result) {
        // You set some action after the item was updated.
      });
  }
  $scope.$on('add', function(event, todo) {
    var add = true;
    angular.forEach($scope.todos, function(value, key) {
      if (value._id == todo._id) {
        $scope.todos[key] = todo;
        add = false;
        return;
      }
    });
    if (add) {
      $scope.todos.push(todo);
    }
  });

  $scope.$on('delete', function(event, id) {
    for (var i = 0; i < $scope.todos.length; i++) {
      if ($scope.todos[i]._id === id) {
        $scope.todos.splice(i, 1);
      }
    }
  });
});
              
            
!
999px

Console