簡體   English   中英

如何使用$ watch使用angularjs引導程序搜索上周

[英]how make search for last week with angularjs bootstrap using $watch

<a href="" ng-click="(search.order_date>=30/11/2016)">Last 7 days</a>

<tr ng-repeat="item in filtered = items | filter:search | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">

AngularJS:

 var app = angular.module('myApp', ['ui.bootstrap']);
    app.filter('startFrom', function () { 
   return function (input, start)
    { 
       if (input) { 
               start = +start; 
               return input.slice(start); 
        } 
          return [];
    };
});


 app.controller('PageCtrl', ['$scope', 'filterFilter', function ($scope, filterFilter) {
$scope.items = [
                {"orderid":1,"skuid":"SKU0010","productimage":"image1","productname":"box","quantity":"1","productprice":"70","totalprice":"100","channelname":"Amazon","order_date":"30/01/2017"}, 
                {"orderid":2,"skuid":"SKU02","productimage":"image2","productname":"box2","quantity":"1","productprice":"700","totalprice":"1000","channelname":"flipkart","order_date":new Date("30/01/2017")}
               ];

// create empty search model (object) to trigger $watch on update
$scope.search = {};

$scope.resetFilters = function () {
    // needs to be a function or it won't trigger a $watch
    $scope.search = {};

};
/*$scope.pastFilters = function () {
    // needs to be a function or it won't trigger a $watch
    //$scope.search = {};


    alert("past");
};*/

// pagination controls
$scope.currentPage = 1;
$scope.totalItems = $scope.items.length;
$scope.entryLimit = 8; // items per page
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.entryLimit);

// $watch search to update pagination
$scope.$watch('search', function (newVal, oldVal) {
    //alert(newVal);
    $scope.filtered = filterFilter($scope.items, newVal);
    $scope.totalItems = $scope.filtered.length;
    $scope.noOfPages = Math.ceil($scope.totalItems / $scope.entryLimit);
    $scope.currentPage = 1;
}, true);


}]);

我認為您需要更具體的格式或嘗試將所有時間戳轉換為類似

<span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>

日期過濾器-更多詳細信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM