如何选择与NG-选项的选择框的默认时间值 [英] How to choose default time value in a select box with ng-options

查看:175
本文介绍了如何选择与NG-选项的选择框的默认时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择框的表单,选择一个企业的工作时间。我想选择上午09点,作为第一个框中的默认值,下午5:00为第二个框的默认值。

I have a form with select boxes to choose a business' working hours. I want to choose 9:00 am as the default value for the first box, and 5:00 pm as the default value for the second box.

下面是的jsfiddle

例如,我有

<select ng-options="hour as (hour | date: 'shortTime') for hour in hours"
  ng-model="start_time" ng-change="update(start_time, $index, 1)">

如果在我的app.js我设置 $ scope.start_time 等于初始化为当前日期和时间为上午9时00 Date对象,默认值是选为该选择框,而不是最后一个值。由于我使用的日期过滤器在shortTime'格式选择框来显示时间,请问这是为什么没有被正确显示的默认值的原因?

If in my app.js I set $scope.start_time equal to a Date object initialized to the current date and time as 9:00 am, the default value is chosen as the last value in the select box instead. Since I am using a date filter to display the time in the select box in the 'shortTime' format, is that the reason why the default value is not being shown correctly?

推荐答案

只需设置模式 START_TIME 权,例如在你的控制器!

Just set the model start_time right, for example in your controller!

<select ng-options="hour as (hour | date: 'shortTime') for hour in hours track by hour"
        ng-model="start_time" ng-change="update(start_time, $index, 1)">

$scope.start_time = new Date(); // set default date in controller

使用最新版本的角度和按部就班地进行,一小时解决了这个问题:的 http://jsfiddle.net/j8xu1h2h/

这篇关于如何选择与NG-选项的选择框的默认时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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