Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  95] [ 6]  / answers: 1 / hits: 21346  / 9 Years ago, sat, august 22, 2015, 12:00:00

I'm new to TypeScript and AngularJS, and I'm trying to convert a date from my API that is something like:



8/22/2015


...to an ISO Date. The date is properly deserialized into a TypeScript property of type Date. However, when I try the following command (in typescript, and this.dateDisplay is of type string)



this.dateDisplay = formats.dateTimeValue.toISOString();


I get the error:




TypeError: formats.dateTimeValue.toISOString is not a function
at dataFormatsTests.js:42
at processQueue (angular.js:14567)
at angular.js:14583
at Scope.$get.Scope.$eval (angular.js:15846)
at Scope.$get.Scope.$digest (angular.js:15657)
at Scope.$get.Scope.$apply (angular.js:15951)
at done (angular.js:10364)
at completeRequest (angular.js:10536)
at XMLHttpRequest.requestLoaded (angular.js:10477)




I've also been to this site and it says my browser supports the toISOString function.



So, my questions is: Why doesn't my browser, or angular, or whatever, recognize the toISOString function?


More From » angularjs

 Answers
6

Although the dateTimeValue was defined as a Date in TypeScript, it was being instantiated at runtime as a string because it was being pulled from the API. Therefore, the TypeScript would compile just fine, but when the javascript ran it was seeing .toISOString() being called against a string, not a Date.


[#65327] Thursday, August 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micheleb

Total Points: 275
Total Questions: 103
Total Answers: 103

Location: Macau
Member since Sat, Jul 11, 2020
4 Years ago
;