javascript - Add entries from the top in to-do list angular -
i have made to-do list in angular posts entered entered fro m top instead bottom.
my code:
html
<a href="{{url.title}}" class="link"> <p class="title">{{url.name}}</p> <p class="url">{{url.title}}</p> </a> </div> <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> </div> </div> </li> js
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(); (var = 0; < mvs.length; i++) { $scope.urls.push({ name: $scope.favurls[mvs[i]].name, title: $scope.favurls[mvs[i]].title, key: mvs[i] }); }; });
you can use unshift() instead of push() when add elements array. adds element @ beginning of array instead of @ end, , since angular view based on model add on top.
Comments
Post a Comment