2017-05-03 1 views
-1

Ich habe eine Konfigurationsdatei, wo ich Konfigurationsparameter speichern.moments Datumsformat in einer Datei

Ich verwende Momentjs, um Datum/Uhrzeit Formatierung zu tun. nun in meiner component.html Datei würde Ich mag, wie etwas tun:

<div> 
     Person DOB : {{Person.DOB | ?config.ShortDate}} 
</div> 

Meine ts-Datei:

import { Config} from "../../../config/config" 

constructor(){ 
    let config:any = Config 
} 

Ich erhalte einen Fehler Was soll ich fehlen oder gibt es Alternativen?

Dank

Edit: nach entsprechender Aktualisierung von sainu zur Verfügung gestellt beantworten

<div> 
    Person DOB : {{Person.DOB | amDateFormat: 'YYYY-MM-DD HH:mm'}} 
</div> 
<div> 
    Person DOB1 : {Person.DOB | date: config.ShortDate}} 
</div> 

gibt mir die Folling Ausgabe:

Person DOB: 1970-01-01 01.00

Person DOB1: AM0DAMteFor0AMt: JJJJ-MM-TT HH: mm

Bitte beachten Sie, dass ich momentjs verwende.

+0

config.ShortDate() in html! –

Antwort

0

fand ich die Antwort selbst.

in html

<div> 
     Person DOB : {{Person.DOB | amDateFormat: config.ShortDate}} 
</div> 

in ts

export class Config{ 
    public static get ShortDate():string {return "YYYY-MM-DD HH:mm"} 
} 

funktioniert perfekt. Danke für Ihre Hilfe.

1

In component.ts

import { Config} from "../../../config/config" 

config:any = Config; 

und in html

<div> 
     Person DOB : {{Person.DOB | date:?config.ShortDate}} 
</div> 

oder

<div> 
     Person DOB : {{Person.DOB | date:'y-MM-dd HH:mm'}} 
</div> 
+0

http://stackoverflow.com/users/5311796/sainu siehe Bearbeiten. –