ui.bootstrap.timepicker不与angularjs ng-model绑定

时间:2015-07-29 06:56:26

标签: javascript angularjs angular-ui-bootstrap

我正在使用ui.bootstrap.timepicker通过用户互动创建和更新数据。

Timepicker适用于创建数据,但它不与ng模型绑定。

以下是传递给Timepicker的数据的示例JSON数组:

{
   "sort":1,
   "name":"Store Timings",
   "_id":"55b78a8658d3060e004fe9f2",
   "delivery":[
      {
         "open":"10:30",
         "close":"20:00",
         "leadTime":"45",
         "interval":"15",
         "message":"Accepting delivery orders",
         "_id":"55b78a8658d3060e004fe9f3",
         "isOpen":true
      }
   ],
   "pickup":[
      {
         "open":"09:30",
         "close":"20:30",
         "leadTime":"30",
         "interval":"15",
         "message":"Accepting takeot orders",
         "_id":"55b78a8658d3060e004fe9f4",
         "isOpen":true
      }
   ],
   "store":[
      {
         "open":"9:30 AM",
         "close":"10:30 PM",
         "message":"We are Open!",
         "_id":"55b78a8658d3060e004fe9f5",
         "isOpen":true
      }
   ],
   "isOnlineOrderOpen":true
}

根据上面的代码,我尝试将ng-value渲染到Timepicker

以下是HTML代码:

<timepicker ng-model="sunday.store[0].open" hour-step="1" minute-step="15" show-meridian="true" ></timepicker>

<timepicker ng-model="sunday.store[0].close" hour-step="1" minute-step="15" show-meridian="true" ></timepicker>

这表明Timepicker为空(我期待值): -  blank Timepicker

1 个答案:

答案 0 :(得分:3)

Timepicker期望您传入Date对象,而不是字符串。

来自Timepicker documentation

  

ng-model:提供时间状态的Date对象。

我正在使用MomentJS将日期从字符串格式化为Date对象。

请参阅MomentJS parse documentation

如果需要,您可以使用相同的库将时间转换回字符串。