从数据库获取数据,显示在date类型的input框中
js代码:
var app = angular.module('myapp', []);
app.controller("getDatas", ['$scope', '$http', '$filter', function ($scope, $http, $filter) {
// 获取信息列表
$http({
url: '/***/***/***',//这里是接口链接
method: 'POST',
data: {
//这里可添加要传递的参数
},
}).success(function (response) {
console.log(response);
if (JSON.parse(response).key == "ok") {
//具体方法来啦
$scope.dateTransform = function (d) {
let date = new Date(d);
let year = date.getFullYear();
let month = date.getMonth() + 1;
month = month < 10 ? '0' + month : month;
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
return year + '-' + month + '-' + day;
};
}
}).error(function () {
console.log('获取信息列表失败')
});
}])
html代码:
<div ng-app="myapp" ng-controller="getDatas">
<div ng-repeat="item in items">
<input type="date" ng-model="item.brith_time" ng-value="dateTransform(item.brith_time)">
</div>
</div>