gpt4 book ai didi

angularjs - 即使日期有效,md-datepicker也会显示红色下划线

转载 作者:行者123 更新时间:2023-12-03 06:56:21 24 4
gpt4 key购买 nike

<md-datepicker name="startDate"  md-is-error="data.isInvalid(Form.startDate)" ng-model="data.startDate" md-placeholder="Start date" required flex="100" flex-lg="50"></md-datepicker>
<div ng-messages="Form.startDate.$error" ng-if="data.isInvalid(Form.startDate)">
<div ng-message="valid">The entered value is not a date!</div>
<div ng-message="required">This date is required!</div>
<div ng-message="mindate">Date is too early!</div>
<div ng-message="maxdate">Date is too late!</div>
</div>


isInvalid : function(formObject) {
return formObject.$invalid && (formObject.$$parentForm.$submitted || formObject.$touched || formObject.$dirty);
}

我正在使用 md-datepicker。当我使用模型填充数据时,我在日期选择器输入框下方看到一条红线。该日期是有效的,但我不确定为什么会这样显示。请参阅随附的屏幕截图以获取更多引用。有人遇到过这个问题吗?非常感谢您的建议。 enter image description here

最佳答案

首先检查您的模块中是否注入(inject)了 ngMessages,第二个 ng-messages 需要一个表单(在您的情况下,在我的片段“myForm”中名为“Form”),最后您必须检查您的 ng-model 是否有 Controller 或你有数据的东西。您还需要一个有效的 md-is-error 表单。

抱歉,我的英语水平无法正确解释您的错误,但您可以检查我的代码片段。

<html>

<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-messages.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-sanitize.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>


<style type="text/css">
.validation-messages {
font-size: 11px;
color: darkred;
margin: 10px 0 0 25px; }
</style>
</head>

<body ng-app="testApp" ng-controller="AppCtrl">
<form name="myForm">
<md-datepicker name="startDate" md-is-error="myForm.startDate.$invalid && myForm.$submitted" ng-model="startDate" md-placeholder="Start date" required flex="100" flex-lg="50"></md-datepicker>
<div class="validation-messages" ng-messages="myForm.startDate.$error">
<div ng-message="valid">The entered value is not a date!</div>
<div ng-message="required">This date is required!</div>
<div ng-message="mindate">Date is too early!</div>
<div ng-message="maxdate">Date is too late!</div>
</div>
</form>
<script type="text/javascript">
var app = angular.module("testApp", ["ngMaterial","ngMessages"])
.controller('AppCtrl', function($scope) {
$scope.startDate= null; //no date on page load });
</script>
</body>

</html>

关于angularjs - 即使日期有效,md-datepicker也会显示红色下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34743553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com