我知道input[date]需要来自 JSON 的日期类型,然后我用 格式化 ngModel 值new Date(json.date),它的工作原理
2015-11-15变得Mon Nov 15 2015 02:00:00 GMT+0200 (CEST)
但我需要该值是2015-11-15我的网络服务的字符串。
确保它与输入一起工作但保持对我的网络服务可用的最佳方法是什么?
(我希望清楚;))
我知道input[date]需要来自 JSON 的日期类型,然后我用 格式化 ngModel 值new Date(json.date),它的工作原理
2015-11-15变得Mon Nov 15 2015 02:00:00 GMT+0200 (CEST)
但我需要该值是2015-11-15我的网络服务的字符串。
确保它与输入一起工作但保持对我的网络服务可用的最佳方法是什么?
(我希望清楚;))
In whatever controller that calls your web service, you can use the same date: filter used in the dom {{myDateObjectThatNeedsToBeFormatted | date: 'yyyy-MM-dd'}} in your controller.
Simply inject the $filter service!!!
//Controller
angular.controller("myControllerThatCallsAWebservice", ["$scope","$filter", "myWebService", myNamedControllerFn]);
function myNamedControllerFn($scope, $filter, myWebService) {
$scope.myDateVariableThatIsBoundToNgModel = new Date(2013, 9, 22);
$scope.isolatedFnForConvertingYourDateToDesiredString = function alwaysNameFunctionsForDebuggingFn() {
return $filter('date')($scope.myDateVariableThatIsBoundToNgModel, "yyyy-MM-dd")
}
myWebService.webServiceCallToDoStuff(
$scope.isolatedFnForConvertingYourDateToDesiredString()
);
}