鉴于返回这样JSON值的WebApi2服务:结合使用的WebAPI angularjs日期和自举日期选择器
{
id: 1109,
effectiveDate: "2014-10-05T00:00:00", // the date is a string (newtonsoft.json)
text: "Duis et rhoncus nibh. Cras rhoncus cursus diam",
fundSource: "Test"
}
我需要的时间出现在结合的角/引导/ date picker正确。
我需要将日期转换为格式yyyy-mm-dd(没有时间),将其绑定到输入框时。 只是一个指向某些文档的指针,解释了将API日期序列化为角度的正确方法。我确信effectiveDate
实际上应该是Date
对象,而不是string
。
<input class="form-control"
type="text"
name="effectiveDate"
ng-model="consultation.effectiveDate"
data-date-picker="yyyy-mm-dd"
placeholder="Date" />
对于completness,返回的JSON值的服务看起来是这样的:
app.factory('Service', ['$http', '$location', '$interpolate', function ($http, $location, $interpolate) {
return {
get: function (account) {
var url = 'api/consultations/{account}';
return $http
.get(Api.format(url, { account: account }))
.then(function (response) { return response.data; });
}
};
}]);
控制器方法调用它像这样:
service.get($scope.urlData.account).then(function(consultations) {
$scope.consultations = consultations;
});
将字符串格式的日期转换为JavaScript Date对象。其余的应该可以正常工作。您可以在JavaScript中使用普通JavaScript进行日期时间处理,但最好使用一些处理跨浏览器兼容性的库。你可以试试moment.js。您的范围变量effectiveDate应该包含Date对象。 – 2014-10-08 04:36:07