2017-05-03 22 views
-1

我有一個配置文件,用於存儲配置參數。單個文件中的momentjs日期格式

export class Config{ 
    public static get ServerUrl():string {return "http://localhost/request.php"} 
    public static get ShortDate():string {return "amDateFormat: 'YYYY-MM-DD HH:mm'"} 
} 

我使用momentjs做日期/時間格式。 現在在我的component.html文件,我想這樣做:

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

我的TS文件:

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

constructor(){ 
    let config:any = Config 
} 

我得到一個錯誤 我缺少什麼或者有什麼辦法?

感謝

編輯: 更新,根據解答sainu

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

後提供給我的folling輸出:

人出生日期:1970-01-01 01:00

Person DOB1:AM0DAMteFor0AMt:YYYY-MM-DD HH:mm

請注意,我正在使用momentjs。

+0

config.ShortDate()in html! –

回答

0

,我發現自己的答案。

在HTML

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

在TS

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

完美的作品。 感謝您的幫助。

1

在component.ts

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

config:any = Config; 

和HTML

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

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

http://stackoverflow.com/users/5311796/sainu請參閱編輯。 –