如何引用第三方 npm 模块?

How to reference a third party npm module?

我已经使用 npm install moment --save 安装了 moment.js,它现在位于我的 node_modules 文件夹中,但我不知道如何在我的应用程序中引用它。

问)当我使用 npm 安装 Ionic 2 应用程序时,如何在我的 Ionic 2 应用程序中使用它?

这是我的 app.ts 的缩略版:

import {App, IonicApp, Platform, Modal, Events, Alert, MenuController} from 'ionic-angular';
import {Type} from 'angular2/core';
import {OnInit, OnDestroy} from 'angular2/core';

// native stuff
import {Keyboard} from 'ionic-native';


// tried this but it can't find the module
//import {moment} from 'moment';

@App({
  templateUrl: 'build/app.html',
  config: {}, // http://ionicframework.com/docs/v2/api/config/Config/
  providers: []
})
class MyApp {
  isLoadingData: boolean = false;
  rootPageToExitOn: string;
  rootPage: Type;
  pages: Array<{icon: string, title: string, component: Type}>;
  showMenu: boolean;

  constructor(
    private app: IonicApp,
    private platform: Platform,
    private menu: MenuController,
    private _events: Events
  ) {
    this.initializeApp();

    // how to use moment() here ...?

  }
}

以下对我有用。

首先,暂时安装类型定义。

typings install moment --save

(注意:不是 --ambient)

然后,解决缺少正确导出的问题:

import * as moment from 'moment';

发件人: