Seven price
asked on
date format angularjs2
My date format returns
/Date(1326258000000)/
in json.st.Date | date:'dd/MM/yyyy'
does not format my date. How can I in angularjs2
Can we see a context?
ASKER
Well maybe in angular2 I need to create a pipe filter for the date format as well. Not like angular 1.
Not sure the bigger picture you would like to see.
Returns Json format data.
Not sure the bigger picture you would like to see.
<table>
<tr *ngFor='#t of list'>
<td>{{t.Name}}</td>
<td>{{ dlist.NotInvestedDate | date: 'dd/MM/yyyy'}}</td>
</tr>
</table>
Using a angularjs Service that loads from mvc Controller.Returns Json format data.
"/Date(1326258000000)/"
your service returns this string, exactly like that? or just the datestamp?
your service returns this string, exactly like that? or just the datestamp?
What does this produce
{{dlist}}
{{dlist}}
ASKER
It returns it just like that.
ASKER
julian typo it suppose to be t not dlist
if that's the exact string, then you need to extract the timestamp before passing to the date filter.
probably best with a regular expression.
returns
you can write a custom filter that gets processed before the date filter, or you can parse your data in the controller, or service. There are many ways to skin this cat.
probably best with a regular expression.
var mre = /\d+/g;
d = parseInt("/Date(1326258000000)/".match(mre,$1))
returns
1326258000000
you can write a custom filter that gets processed before the date filter, or you can parse your data in the controller, or service. There are many ways to skin this cat.
julian typo it suppose to be t not dlistLine 4 ????
<td>{{ dlist.NotInvestedDate | date: 'dd/MM/yyyy'}}</td>
We need to see what is in dlist
ASKER
Example
in angular1 I could parse the data JSON.parse(value); when returning from api because the data returned "{\"_body\":\"[{\\\"ID\\\" :33,\\\"Na m\\\":\\\" SusCampbel l\\\"NotIn vestedDate ":"2012-01 -11T00:00: 00"",
getboard(): Observable<Idata[]> {
return this._http.get(this._dashU rl)
.map((response: Response) => <Idata[]>response.json())
// .do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
Julian I see.
nothing in dlist. ok. please.
<td>{{ t.NotInvestedDate | date: 'dd/MM/yyyy'}}</td>
Kyle not sure to make this happen in a angularjs2 service?
in angular1 I could parse the data JSON.parse(value); when returning from api because the data returned "{\"_body\":\"[{\\\"ID\\\"
getboard(): Observable<Idata[]> {
return this._http.get(this._dashU
.map((response: Response) => <Idata[]>response.json())
// .do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
Julian I see.
nothing in dlist. ok. please.
<td>{{ t.NotInvestedDate | date: 'dd/MM/yyyy'}}</td>
Kyle not sure to make this happen in a angularjs2 service?
Is that your returned data?
how are you getting
Date(1326258000000)
From that.
how are you getting
Date(1326258000000)
From that.
you can provide multiple filters in your expression.
{{ t.NotInvestedDate | my_regex_filter | date:'dd/MM/yyyy'}}
write a filter that takes your string as input and returns the timestamp using the regular expression
{{ t.NotInvestedDate | my_regex_filter | date:'dd/MM/yyyy'}}
write a filter that takes your string as input and returns the timestamp using the regular expression
but like Julian pointed out, your API appears to be returning a date string not what you stated earlier.
what is the exact value rendered by t.NotInvestedDate?
what is the exact value rendered by t.NotInvestedDate?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks I already thought this was the fix. thanks
ASKER
thanks