我想在angularjs项目中使用bootstrap callback validator进行日期范围验证。当回调函数是简单的javascript函数时,一切正常。但我需要从角度控制器调用函数来从范围中获取数据。 我怎么能这样做?
查看:
<div class="form-group inputGroupContainer" ng-controller="DatepickerCtrl">
<label for="date">Date of Birth</label>
<p class="input-group">
<input type="text" name="date1" placeholder="DD/MM/YYYY" class="form-control"
ui-date="{dateFormat: 'dd/MM/yyyy'}" ui-date-format="dd/MM/yyyy" datepicker-popup="{{format}}"
ng-model="user.Personal.BirthDate"
data-bv-callback="true"
data-bv-callback-message="Invalid date"
data-bv-callback-callback={{checkBirthDate}}
is-open="opened" 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>
</div>
角度控制器中的功能(不工作):
$scope.checkBirthDate = function () {
return moment($scope.user.Personal.BirthDate, 'DD/MM/YYYY', true).isBefore(new Date());
};
javascript中的回调函数(工作正常):
function checkBirthDate(value, validator) {
return moment(value, 'DD/MM/YYYY', true).isBefore(new Date());
};