gpt4 book ai didi

angularjs - 如何使用ui-mask从 Angular 输入中获取模型中的掩盖日期?

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

我有一个 View ,要求用户在文本框中输入他们的生日。

我正在使用UI-Utils中的mask指令。

我的 View 中包含以下输入元素:

<input ui-mask="99/99/9999" placeholder="MM/DD/YYYY" type="text" name="uBirthdate" ng-model="user.birthdate" required/>

在我的 Controller 中,我将范围设置为
myApp.controller('HomeCtrl', function ($scope, myService){

$scope.user = registerService.getCurrentUser();

$scope.submit = function () {
//do something with $scope.user.birthdate
};

}
});

我的问题是,在我的 Controller 中,birthdate属性包含来自输​​入的值,而没有掩码字符,因此输入为

View 中的 11/20/1980在$ scope中作为属性变为 11201980
如何确定我的 Controller 中有有效的屏蔽日期?仅供引用,此日期将在POST请求中作为JSON发送到我的服务器。

最佳答案

升级到最新的angular-ui并使用以下语法

ui-mask="99/99/9999" model-view-value="true"

model-view-value会将 mask 保留在模型对象上。

关于angularjs - 如何使用ui-mask从 Angular 输入中获取模型中的掩盖日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20999141/

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