Home Ask Login Register

Developers Planet

Your answer is one click away!

user1937021 February 2016

Add entries from the top in to-do list angular

I have made this to-do list in angular but would like the posts entered to entered fro m the top instead the bottom.

my code:


                  <a href="{{url.title}}" class="link">
                      <p class="title">{{url.name}}</p>
                      <p class="url">{{url.title}}</p>
              <div class="col-md-4 delete m-b-2">
                    <!--a href="javascript:" ng-click="edit($index)" type="button" class="btn btn-primary btn-sm">Edit</a-->
                    <a href="javascript:" class="btn btn-danger btn-sm" ng-click="del($index)">Delete</a>



var urlFire = angular.module("UrlFire", ["firebase"]);
function MainController($scope, $firebase) {
  $scope.favUrls = $firebase(new Firebase('https://lllapp.firebaseio.com/'));
  $scope.urls = [];
  $scope.favUrls.$on('value', function() {
  $scope.urls = [];
  var mvs = $scope.favUrls.$getIndex();
    for (var i = 0; i < mvs.length; i++) {
        name: $scope.favUrls[mvs[i]].name,
        title: $scope.favUrls[mvs[i]].title,
        key: mvs[i]


Zonedark February 2016

You can use unshift() instead of push() when you add elements to your array. It adds the element at the beginning of your array instead of at the end, and since your angular view is based on the model it will add it on top.

erichardson30 February 2016

Use $scope.urls.splice(index_to_insert,0, object); so in your case you could do

var obj = {
        name: $scope.favUrls[mvs[i]].name,
        title: $scope.favUrls[mvs[i]].title,
        key: mvs[i]
$scope.urls.splice(0,0, obj);

Post Status

Asked in February 2016
Viewed 3,668 times
Voted 12
Answered 2 times


Leave an answer

Quote of the day: live life