title: Moving items in a Firebase Array
body: <p>I have been playing around with the firebase API and have hit a bit of a wall. </p>
  
  <p>The problem is that I'm trying to move an item up or down an array but can't seem to figure out how to do this in the Firebase API.</p>
  
  <p>Here is my controller</p>
  
  <pre><code>angular.module('aceTrainingApp')
    .controller('AdminController',['$scope','FirebaseService', function ($scope, FirebaseService) {
  
      $scope.posts = FirebaseService.getPosts();
      $scope.localPosts = $scope.posts; //is this Right??
      $scope.newPost = {name: '', body: ''};
  
          $scope.remove = function (id) {
              FirebaseService.removePost(id);
          };
  
          $scope.updatePost = function (id) {
              FirebaseService.updatePost(id);
              $scope.newPost = {name: '', body: ''};
          };
  
          $scope.addPost = function() {
              FirebaseService.addPost(angular.copy($scope.newPost));
          };
  
  //only trying to get moveDown working first
  //            $scope.moveUp = function(post) {
  //            var crntPos = $scope.posts.indexOf(post);
  //           if (crntPos &gt; 0) {
  //                $scope.posts.splice(crntPos, 1);
  //                $scope.posts.splice(crntPos - 1, 0, post);
  //            }
  //        };
  
      $scope.moveDown = function(post) {
          var crntPos = $scope.localPosts.indexOf(post);
          if (crntPos &lt; $scope.localPosts.length) {
              $scope.localPosts.splice(crntPos, 1);
              $scope.localPosts.splice(crntPos + 1, 0, post);
              FirebaseService.updateAllPosts($scope.localPosts);
          }
      };
    }]);
  </code></pre>
  
  <p>And here is the service</p>
  
  <pre><code>angular.module('aceTrainingApp').factory('FirebaseService', [ '$firebase', function($firebase){
  
  var ref = new Firebase('https://acetrainingsolutions.firebaseio.com/');
  var posts = $firebase(ref).$asArray();
  
  var getPosts = function(){
      return posts;
  };
  
  var removePost = function(id){
      posts.$remove(id);
  };
  
  var updatePost = function(post){
      posts.$save(post);
  };
  
  
  
  var addPost = function(index){
      posts.$add(index);
  };
  
  return {
      getPosts: getPosts,
      removePost: removePost,
      updatePost: updatePost,
      addPost: addPost
  };
  }]);
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>    &lt;li ng-repeat="post in localPosts track by $index"&gt;
          &lt;input type="text" ng-model="post.name" ng-blur="updatePost($index)"&gt;
          &lt;input type="text" ng-model="post.body" ng-blur="updatePost($index)"&gt;
          &lt;button type="button" class="close space" ng-click="moveDown(post)"&gt;&amp;DownArrow;&lt;/button&gt;
          &lt;button type="button" class="close space" ng-click="moveUp(post)"&gt;&amp;UpArrow;&lt;/button&gt;
          &lt;button type="button" class="close space" ng-click="remove($index)"&gt;&amp;times;&lt;/button&gt;
      &lt;/li&gt;
  </code></pre>
  
  <p>The problem is that the splice method only works on the view as mentioned in the Firebase docs. Can someone help me fix the moveUp and moveDown functions?</p>
  
  <p>Cheers</p>