在角度js中发出来自服务器请求的日期值

时间:2015-11-08 21:02:13

标签: javascript angularjs

我正在使用角度j来显示来自服务器的数据。它工作正常,但问题是由于输入类型"日期"日期值没有显示。当我将输入类型更改为" text"有用。以下是我的代码:

HTML:

OID=1

js code

<body ng-app="myApp" ng-controller="customersCtrl">
    <input type="date" ng-model="x.sdate">
</body>

请告诉我缺少什么

1 个答案:

答案 0 :(得分:0)

正如我的评论所述,<input type="date"> 的模型必须Date个对象。

您需要将API中的数据从字符串转换为Date。例如

$http.get('http://socialdeal4u.com/demo/survey/api-delete.php', {
    params: {id: param},
}).then(function(response) {
    $scope.x = response.data;
    $scope.x.sdate = new Date($scope.x.sdate);
});

这当然假设API响应中的sdate字符串符合ISO 8601标准,或者在Date构造函数中可用。