cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <body ng-controller="DemoCtrl" class="container" ng-app="myTodoApp" ng-init="readList()">
  <h2>Backand Real-time Todo Example</h2>
  <h4>Try it by opening two browsers and update / add / remove a TODO</h4>
  <br/>
    <!-- Todos input -->
    <form role="form" ng-submit="create({'description': description}); description = '';">
        <div class="row">
            <div class="input-group">
                <input type="text" ng-model="description" placeholder="What needs to be done?" class="form-control">
                <span class="input-group-btn">
                  <input type="submit" class="btn btn-primary" value="Add" ng-disabled="!description">
                </span>
            </div>
        </div>
    </form>
    <p></p>

    <!-- Todos list -->
    <div>
        <p  class="input-group"
            ng-repeat="todo in todos | orderBy:'-id'"
            style="padding:5px 10px; cursor: move;"
            ng-class="{'todo-completed': todo.completed}">
            <span class="input-group-btn">
                <button class="btn"><input type="checkbox" class="btn btn-primary" ng-model="todo.completed" ng-click="update(todo)"></button> 
            </span>
            <input  type="text"
                    ng-disabled="todo.completed"
                    ng-model="todo.description"
                    ng-change="update(todo)"
                    ng-model-options="{updateOn: 'blur'}"
                    class="form-control" >
            <span class="input-group-btn">
                <button class="btn btn-danger" ng-click="delete(todo)" aria-label="Remove">X</button>
            </span> 
        </p>
    </div>
  </div>
</body>  
  
  
  
            
          
!
            
              var myApp = angular.module('myTodoApp', ['backand']);

myApp.config(function (BackandProvider) {
    BackandProvider.setAppName('backandtodoapp');
    BackandProvider.setSignUpToken('76a0ed19-c9d4-405a-9e20-493d637b131c');
    BackandProvider.setAnonymousToken('6adbc622-36b5-496c-b288-19ea28816f10');
    BackandProvider.runSocket(true);
})

myApp.controller('DemoCtrl', ['$scope', '$http', 'Backand', DemoCtrl]);

function DemoCtrl($scope, $http, Backand) {

    var baseUrl = '/1/objects/';
    var objectName = 'todo';
  
    $scope.todos = null;
  
    Backand.on('todo_updated', function (data) {
      //Get the event and refresh the list
      console.log("event:" + data);
      $scope.readList();
    });
  
    $scope.readList = function () {
      return $http ({
        method: 'GET',
        url: Backand.getApiUrl() + '/1/objects/todo',
        params: {
          pageSize: 50,
          pageNumber: 1,
          filter: null,
          sort: '[{fieldName:\'id\', order:\'desc\'}]'
        }
      }).then(function(response) {
        $scope.todos = response.data.data;
      });
    };

    $scope.readOne = function (id) {
      return $http({
        method: 'GET',
        url: Backand.getApiUrl() + baseUrl + objectName + '/' + id
      }).then(function(response) {
        return response.data;
      });
    };

    $scope.create = function (newTodo) {
      return $http({
        method: 'POST',
        url : Backand.getApiUrl() + baseUrl + objectName,
        data: newTodo,
        params: {
          returnObject: true
        }
      }).then(function(response) {
        //$scope.readList();
        return response.data;
      });
    };

    $scope.update = function (todo) {
      return $http({
        method: 'PUT',
        url : Backand.getApiUrl() + baseUrl + objectName + '/' + todo.id,
        data: todo
      }).then(function(response) {
        //$scope.readList();
        return response.data;
      });
    };

    $scope.delete = function (todo) {
      return $http({
        method: 'DELETE',
        url : Backand.getApiUrl() + baseUrl + objectName + '/' + todo.id
      }).then(function(response) {
        $scope.readList();
        return response.data;
      });
    };

}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console