我已经使用npm install moment -save安装了moment.js,它现在在我的node_modules文件夹中,但我不知道如何在我的应用程序中引用它.
问)当我使用npm安装时,如何在Ionic 2应用程序中使用moment.js?
这是我的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
(注意:不 – 相关)
然后,解决缺乏适当的出口:
import * as moment from 'moment';