Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <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>  
  
  
  
              
            
!

CSS

              
                
              
            
!

JS

              
                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);
    BackandProvider.setAppName('backandcrud');
    BackandProvider.setSignUpToken('');
    
    BackandProvider.setAnonymousToken('7fabbc14-0e42-4c24-a873-6ead28606a29');
    BackandProvider.runSocket(true);
})

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

function DemoCtrl($scope, Backand) {

    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() {
      var params = {
        pageSize: 30,
        pageNumber: 1,
        filter: null,
        sort: [{fieldName:'id', order:'desc'}]
      };    
      Backand.object.getList(objectName, params).then(function(response) {
        $scope.todos = response.data;
      });
    };  
    $scope.readOne = function(id) {
      Backand.object.getOne(objectName, id).then(function(response) {
        return response.data;
      });
    };

    $scope.create = function(newTodo) {
      console.log("create new socket");
      Backand.object.create(objectName, newTodo, {returnObject: true}).then(function(response) {
        return response.data;
      });
    };

    $scope.update = function(todo) {
      console.log(todo);
      Backand.object.update(objectName, todo.id, todo).then(function(response) {
        //$scope.readList();
        return response.data;
      });
    };

    $scope.delete = function(todo) {
      Backand.object.remove(objectName, todo.id).then(function(response) {
        //$scope.readList();
        return response.data;
      });
    };
  
    $scope.readList();

}
              
            
!
999px

Console