2016-07-22 57 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(); 

,並確保當視圖渲染控制器被調用。