Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input doesn't display initial value with ng-model #218

Closed
Maciejszuchta opened this issue Jan 22, 2018 · 5 comments
Closed

Input doesn't display initial value with ng-model #218

Maciejszuchta opened this issue Jan 22, 2018 · 5 comments

Comments

@Maciejszuchta
Copy link

Hello
I noticed a weird bug. When I load object with initial DateTime somehow it doesn't display date property.

My object date looks like this :

    `"value": "2017-10-30T09:52:49.105Z"`

I thought maby I incorreclty set the format of datepicker when initializing but when I select the date and time from calendar it is stored with propper format.
<input type="text" class="form-control" ng-disabled="!(item.selected || item.requireCheckbox == false)" ng-model="item.value" datetime-picker="yyyy-MM-ddTHH:mm:ss.sss'Z'" is-open="item.showFlag" style="width: 100%" ng-style="item.value != item.oldValue && {'border':'2px solid #42aaf4'} || {'border':'1px solid #ccc'}">

If I remove datetime-picker directive from input the date from the object is displayed properly.

Please help

@Gillardo
Copy link
Owner

Can you create a plunkr to replicate? Is your value a date object? or a date formatted string? It should be a date object

@Maciejszuchta
Copy link
Author

It is a string formatted as a date.

@Gillardo
Copy link
Owner

needs to be a date object. Try changing it to const myDate = new Date(yourValue) and then use myDate in the component.

@Maciejszuchta
Copy link
Author

@Gillardo parsing string to date object helped.
What I did was:
<input type="text" ng-init="item.value = parseDate(item.value); ....."

And parseDate looks like this:

$scope.parseDate= function(date) { try { date = new Date(date); } catch (err) { console.log(err); } return date; }

Thanks for advice :)

@Gillardo
Copy link
Owner

No problem! glad its working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants