Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:在模式中验证-最小日期_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS:在模式中验证-最小日期

Javascript AngularJS:在模式中验证-最小日期,javascript,angularjs,Javascript,Angularjs,我正在尝试验证日期输入,但我的最小日期检查不起作用。非常感谢您的帮助 <script type="text/ng-template" id="instructor-form.html"> <form name="instructorForm" novalidate ng-submit="ok('save')"> <div class="modal-header"> <h3 ng-hide="!item.In

我正在尝试验证日期输入,但我的最小日期检查不起作用。非常感谢您的帮助

<script type="text/ng-template" id="instructor-form.html">
    <form name="instructorForm" novalidate ng-submit="ok('save')">
        <div class="modal-header">
            <h3 ng-hide="!item.InstructorId">Edit Instructor</h3>
            <h3 ng-hide="item.InstructorId">New Instructor</h3>
        </div>
        <div class="modal-body">
            <div class="row-fluid">
                <div class="span5">
                    <div class="control-group" ng-class="{error: instructorForm.lic.$invalid && instructorForm.lic.$dirty}">
                        <label for="lic">License Expiration Date *</label>
                        <div class="input-prepend input-block-level">
                            <span class="add-on"><i class="icon-calendar"></i></span>
                            <input name="lic" type="date" ng-model="item.LicenseExp" required min="1900-01-01">
                        </div>
                        <span ng-show="instructorForm.lic.$dirty">
                            <span ng-show="instructorForm.lic.$error.required" class="help-inline">License Exp. is required</span>
                        </span>
                        <span ng-show="instructorForm.lic.$error.min">Not a valid date! Please enter a date after 1900.</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <span ng-show="instructorForm.$invalid">* Please enter all required information before saving.</span>
            <button class="btn btn-primary" ng-disabled="instructorForm.$invalid" type="submit">Save</button>
            <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
        </div>
    </form>
</script>

编辑讲师
新教员
许可证到期日*
需要许可证扩展
不是有效日期!请输入1900之后的日期。
*保存前请输入所有必需的信息。
拯救
取消
instructorForm.lic.$error.min是我遇到问题的地方$脏兮兮的,$error.required还可以,但是,$error.min似乎不做下蹲

控制器代码:

$scope.editInstructor = function (orig) {
    dialogScope.item = angular.copy(orig);
    dialogScope.item.LicenseExp = moment(orig.LicenseExp).format('YYYY-MM-DD');

    var modal = $modal.open({
        templateUrl: 'instructor-form.html',
        controller: 'ModalCtrl',
        resolve: { childScope: function () { return dialogScope; } }
    });

    modal.result.then(function (result) {
        if (result === 'save') {
            var absMinDate = new moment('1900-01-01');

            if (moment(absMinDate).isBefore(dialogScope.item.LicenseExp)) {
                // set in our collection for immediate user feedback
                $scope.instructors[idxof(orig)] = dialogScope.item;
                pubSub.publish('highlight', orig.InstructorId);

                // call service to save on server
                dialogScope.item.$save(function(updated) {
                    if (updated.error) {
                        // if failure, reset original in collection
                        $scope.instructors[idxof(orig)] = orig;
                        pubSub.publish('highlight', orig.InstructorId);

                        // show error
                        notificationService.error('<h4>An error occurred updating the instructor.</h4>' + updated.error);
                    } else {
                        // if success, show message
                        notificationService.success('Instructor updated successfully.');
                        cacheManager.removeResource('instructor');
                    }
                });
            } else {
                // show error
                // notificationService.error('<h4>Please enter a date after January 1st, 1900.</h4>');
                // This doesn't work, as it shuts the modal and then displays an error - useless to the user.
            }
        }
    });
};
$scope.edit讲师=函数(orig){
dialogScope.item=角度复制(原始);
dialogScope.item.LicenseExp=力矩(原始LicenseExp).格式('YYYY-MM-DD');
var modal=$modal.open({
templateUrl:“讲师表单.html”,
控制器:“ModalCtrl”,
解析:{childScope:function(){return dialogScope;}}
});
modal.result.then(函数(结果){
如果(结果=='save'){
var Abmindate=新力矩('1900-01-01');
if(瞬间(缺席).isBefore(dialogScope.item.LicenseExp)){
//在我们的集合中设置,以便立即获得用户反馈
$scope.instructors[idxof(orig)]=dialogScope.item;
pubSub.publish(“突出显示”,原始指令ID);
//调用服务以在服务器上保存
dialogScope.item.$save(功能(已更新){
如果(已更新。错误){
//如果失败,则重置集合中的原始文件
$scope.instructors[idxof(orig)]=orig;
pubSub.publish(“突出显示”,原始指令ID);
//显示错误
notificationService.error('更新讲师时出错。'+Update.error);
}否则{
//如果成功,则显示消息
notificationService.success('讲师更新成功');
cacheManager.removeResource(“讲师”);
}
});
}否则{
//显示错误
//notificationService.error('请输入1900年1月1日之后的日期');
//这不起作用,因为它关闭了模式,然后显示一个错误-对用户没有用处。
}
}
});
};

你能发布你的控制器代码吗?它很长,但肯定。。。让我看看……我只需要读一下你在哪里设置
instructorForm.lic.$error.min
我不太确定整个“你在哪里设置”部分-我对Angular是如此的陌生,以至于我甚至都不会说我对它是新的。我不必设置
instructorForm.lic.$invalid
instructorForm.lic.$dirty
-为什么我必须设置
instructorForm.lic.$error.min
?您不必设置它。Angular内置了对上的min属性的支持。