0

I receive some json data from a web API. This json data consists of a series of datetimes.

I want to be able to select a particular datetime from a dropdown list. There is no problem populating the list, but the formatting is incorrect, and I don't know how to make it right.

The selected datetime is going to be used afterwards.

I'm using Angular and don't mind using some other 3rdparty tool like moment.js

Currently it looks like this:

enter image description here

EDIT: I'm populating the dropdown in the following way:

<select class="inputIndkald" id="tidspunktDropdown" ng-model="indkald.tidspunkt" ng-options="tidspunkt.dateTime for tidspunkt in indkaldTidspunkt"><option value="">Vælg...</option></select>

I hope you guys can help me out.

2
  • That's an ambiguous format. ISO 8601 says dates without a zone are local, ECMA-262 ed 5 says they're UTC (but the draft ed 6 says local). What are you treating them as? Commented Nov 13, 2014 at 14:55
  • Those datetimes are local. Commented Nov 13, 2014 at 14:59

1 Answer 1

5

[..old answer not relevant ...]

UPDATE:

I have never done this myself but have you tried something like:

<select 
    class="inputIndkald" 
    id="tidspunktDropdown" 
    ng-model="indkald.tidspunkt" 
    ng-options="tidspunkt.dateTime as tidspunkt|date:'HH:mm:ss dd.MM.yyyy' for tidspunkt in indkaldTidspunkt ">

    <option value="">Vælg...</option>
</select>
Sign up to request clarification or add additional context in comments.

4 Comments

Updated the answer with a code snippet, and tried your example, but nothing happens when adding that filter.
No I did not try that, but it looks like a promising way to do it. In the meantime I implemented a converter using Moment. Now I take the repsonse, parse it using Moment to another array with the new formatting, but also saving the old value. This way I can use my displayvalue and still keep the old value that I have to use a little while later. Thank you though!
Just tried the above example, but it did not work unfortunately. The dropdown list just gets filled with [object Object] for each row.
Update: The following works great: ng-options="tidspunkt.dateTime | date: 'HH:mm' for tidspunkt in indkaldTidspunkt ">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.