无法从AngularJS中的控制器设置日期选择器日期 [英] Can't set datepicker date from controller in AngularJS

查看:60
本文介绍了无法从AngularJS中的控制器设置日期选择器日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按一个按钮创建一个AngularJS datepicker.我正在使用 bootstrap-ui控件.该控件有效(单击按钮弹出,我可以选择一个日期),但是我似乎无法从范围中设置初始日期(因此,当它第一次打开时,指定的日期已经选择).

I am trying to create an AngularJS datepicker on the push of a button. I am using this bootstrap-ui control. The control works (pops up on the click of a button, and I can select a date), but I can't seem to set the initial date back from the scope (so that when it is first opened, the designated date is already selected).

我在Chrome控制台中收到的错误是:

The error I get in the Chrome console is:

Datepicker指令:"ng-model"值必须是Date对象,自1970年1月1日以来的毫秒数或代表RFC2822或ISO 8601日期的字符串.

Datepicker directive: "ng-model" value must be a Date object, a number of milliseconds since 01.01.1970 or a string representing an RFC2822 or ISO 8601 date.

玉器:

button(type="button" ng-model="date.from" btn-radio="'From'" ng-click="date.openFromPopup($event);" show-weeks="false" show-button-bar="false" datepicker-popup = "date.format" is-open = "date.fromOpened" min = "date.minDate" max = "date.today") From

由于我在 $ scope.date.from 上进行过监视,因此可以确认所选日期是正确的,但是我永远无法从控制器进行设置.有什么想法吗?

Since I have a watch on $scope.date.from, I can confirm that the selected date is correct, but I can never set it from the controller. Any ideas?

AngularJS控制器:

AngularJS controller:

$scope.date = {};

$scope.date.format = "yyyy/MM/dd";
$scope.date.opened = false;
$scope.date.from = new Date();
$scope.date.today = new Date();
$scope.date.minDate = null;
$scope.date.fromOpened = false;

$scope.$watch('date.from', function(v) {
if(v){
     alert(v);
}
});

推荐答案

在angular-ui页面的示例中,它表示要像这样使用它...

In the example on the angular-ui page, it says to use it like this...

$scope.from = function() {
    $scope.dt = new Date();
};
$scope.from();

行得通吗?

这篇关于无法从AngularJS中的控制器设置日期选择器日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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