babaji01234 0 Newbie Poster

I am newbie to Angular Js. I am trying to use date range filter between two dates which will show the stock within that date.
Here is my code.
HTML Code:

<div ng-app="myApp" ng-controller="myCtrl"> <div> <table> <tr> <td>Start Date</td> <td><input type="text" name="S_Date" ng-model="startDate"/></td> <td>End Date</td> <td><input type="text" name="E_Date" ng-model="endDate"/> </tr> </table> </div> <table> <tr> <th>Date</th>.
        <th>Stock</th> </tr> <tr ng-repeat="subject in records |myfilter:startDate:endDate"> <td>{{ subject.name * 1000|date:'dd-MM-yyyy'}}<td> <td>{{ subject.marks }}</td> </tr> </table>

Angular js:

<script>
var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope) {
       $scope.records = [
       {
            "name" : "2016-08-01",
            "marks" : 250
        },{
            "name" : "2016-08-02",
            "marks" : 150
        },{
            "name" : "2016-08-03",
            "marks" : 100
        },{
            "name" : "2016-08-04",
            "marks" : 150
        },{
            "name" : "2016-05-01",
            "marks" : 750
        },{
            "name" : "2016-05-02",
            "marks" : 1500
        },{
            "name" : "2016-03-03",
            "marks" : 500
        },{
            "name" : "2016-04-04",
            "marks" : 650
        }
    ]


    /* function parseDate(input) {
  var parts = input.split('-');
  return new Date(parts[2], parts[1]-1, parts[0]); 
}*/
    app.filter("myfilter", function() {
  return function(items, from1, to) {

    var df = parseDate(from1);
        var dt = parseDate(to);
        alert(df)
        alert(dt)
        var result = [];        
        for (var i=0; i<items.length; i++){
            var tf = new Date(items[i].startDate * 1000),
                tt = new Date(items[i].endDate * 1000);
            if (tf > df && tt < dt)  {
                result.push(items[i]);
            }
        }            
        return result;
  };
});
});
</script>

Please advice what is wrong with this code.Please help me.Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.