2

I'm trying to filter a table using a daterange, but can't get the model to update so it doesn't know what date I picked.

This is the HTML for the datepicker popup:

<label>From:</label> 
 <p class="input-group" style="width:200px">
   <input type="text" class="form-control" uib-datepicker-popup = "{{format}}" ng-model="dt" is-open="status.opened"
                                           min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)"
                                           ng-required="true" close-text="Close"/>
     <span class="input-group-btn">
          <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
     </span>
 </p>

The JS code in my controller:

(function ()
{
'use strict';

angular.module('aml-tech-dashboard.successful-emails').controller('datepickerController', function ($scope) {
    $scope.dt = '';
    $scope.status = {
        opened: false
    };

    $scope.format = "yyyy-MM-dd"
    $scope.minDate = new Date();
    $scope.dateOptions = {
        //formatYear: 'yy',
        startingDay: 1
    };

    $scope.open = function ($event) {
        $scope.status.opened = true;

    };

    });

})();

Table:

<tr ng-repeat = 'file in files | startFrom: dt'>
2
  • Hi Andreea. I notice that $scope.dt is not set to any value inside your $scope.$watch function Commented Jul 22, 2016 at 8:58
  • Hi, I removed that, It was something I used to just log it to my console and see if it detects changes when I select different dates. Assigning a value to $scope.dt didn't change anything though Commented Jul 22, 2016 at 9:00

2 Answers 2

1

Your tr element is wrong. It should look like this:

<tr ng-repeat="file in files | startFrom: dt"></tr>

You also have a mistake in the uib-datepicker-popup directive. It should look like this:

uib-datepicker-popup="{{format}}" 

This is assuming you have defined the startFrom filter elsewhere in your module, as it is not a built-in Angular filter.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, changed that, but it's still not updating the model. I think it's something wrong with my controller
Do you have a startFrom filter defined somewhere?
the uib-datepicker-popup directive thing was just me being bad at copy pasting, oops.
As I said, there is no built in startFrom filter in Angular, so that could be it
You're right, I changed that and it works now. Thanks :)
0

try this:

$scope.dt = new Date(); 

and make sure that the controller is invoked when the view render.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.