Angularjs最小最大日期 [英] Angularjs min max date

查看:474
本文介绍了Angularjs最小最大日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置日期的最小 - 最大动态地angularjs。我的意思是,如果我设置angularjs最小日期应自动绑定到前端。 
这是我在我的控制器中写道
$ scope.from1date ='2016年12月31日;
        $ scope.to1date ='2016年12月31日;
Whenver我改变我的分日期在我的控制器应当反映在我的frontendpage以及如何做到这一点...

How to Set min-max of dates dynamically in angularjs. I mean if I set the min date in angularjs it should be binded automatically to frontend. this is what i wrote in my controller $scope.from1date='2016-12-31'; $scope.to1date='2016-12-31'; Whenver I change my min date in my controller it should be reflected in my frontendpage and how to do that...

推荐答案

这似乎为我工作。你已经采取了看看从W3Schools的angularjs控制器本教程?我猜你的整体逻辑,都可能是错误/车。特别是,这个code段从教程正是你需要的格式(你甚至可以把它复制粘贴到您的源$ C ​​$ C),并把您的具体code你在它您的文章的评论规定。然后,你可能会发现,你已经走了错误的。

It seems to work for me. Have you taken a look at this tutorial on angularjs controllers from W3Schools? I'm guessing your overall logic might somehow be wrong/buggy. Particularly, this code snippet from the tutorial is exactly what you need for the formatting (you could even copy-paste it to your source code) and put your exact code you provided in the comment of your post in it. Then you might notice where you've gone wrong.

我希望这有助于 - 让我知道如何去

I hope this helps – let me know how it goes!

编辑:我明白了,这里就是你出了问题。你需要使用一个Date对象(见日期在MDN文档)。

I see, here's where you went wrong. You need to use a Date object (see Date in the MDN Docs).

简单地说,这样的事情应该这样做:

Simply, something like this should do it:

$scope.from1date= new Date(2015, 12, 20); //'2016-12-20';
$scope.to1date= new Date(2015, 12, 31); //'2016-12-31';

这篇关于Angularjs最小最大日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆