2016-07-22 48 views
2

我想使用daterange过滤表,但不能更新模型,因此它不知道我选择了哪个日期。Angular JS datepicker不更新模型

这是日期选择器弹出窗口中的HTML:

<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> 

JS代码在我的控制器:

(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; 

    }; 

    }); 

})(); 

表:

<tr ng-repeat = 'file in files | startFrom: dt'> 
+0

嗨安德列亚。我注意到$ scope.dt没有设置为你的$范围内的任何值$ watch function –

+0

嗨,我删除了,这是我用来记录它到我的控制台,看看它是否检测到变化时,我选择不同日期。为$ scope.dt赋值并不会改变任何内容 – Andreea

回答

1

tr元素是错误的。它应该看起来像这样:

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

您在uib-datepicker-popup指令中也有错误。它应该是这样的:

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

这是假设你有你的模块中其它地方定义的startFrom过滤器,因为它不是一个内置的角度滤波器。

+0

谢谢,改变了这一点,但它仍然没有更新模型。我认为这是我的控制器有问题 – Andreea

+0

你有一个'startFrom'过滤器定义的地方? – Aron

+0

uib-datepicker-popup指令只是让我在复制粘贴时不好,哎呀。 – Andreea

0

试试这个:

$scope.dt = new Date(); 

,并确保当视图渲染控制器被调用。