如何使用moment.js库角2打字稿应用程序? [英] How to use moment.js library in angular 2 typescript app?

查看:146
本文介绍了如何使用moment.js库角2打字稿应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用打字稿绑定使用它:

I tried to use it with typescript bindings:

npm install moment --save
typings install moment --ambient -- save

test.ts:

test.ts:

import {moment} from 'moment/moment';

和无:

npm install moment --save

test.ts:

test.ts:

var moment = require('moment/moment');

但是,当我打电话moment.format(),我得到一个错误。
应该是简单的,有谁能够提供命令行/进口相结合,将工作?

But when I call moment.format(), I get an error. Should be simple, can anybody provide a command line/import combination that would work?

推荐答案

下面为我工作。

首先,安装类型定义的时刻。

First, install the type definitions for moment.

分型安装时刻--save

(注意:不是 - 环境

然后,以解决缺乏适当的出口:

Then, to work around the lack of a proper export:

import * as moment from 'moment';

这篇关于如何使用moment.js库角2打字稿应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆