在Angular 6中导入时刻

tol*_*lga 0 javascript momentjs angular

我用角6进口了一下:

import moment from 'moment'
Run Code Online (Sandbox Code Playgroud)

let formatted = moment(startDate).tz(timezone).format();
Run Code Online (Sandbox Code Playgroud)

这似乎工作正常...但ng服务输出以下错误:

Module '"/my/project/node_modules/moment/moment"' has no default export.
Run Code Online (Sandbox Code Playgroud)

好的,我理解这个错误; 它说那个时刻不会被导出为默认值...但是当我尝试以这种方式导出时:

import { moment } from 'moment'
Run Code Online (Sandbox Code Playgroud)

但是,错误说,那个时刻实际上是一个对象,而不是一个功能.

它的第一步是如何工作的呢?我应该如何导入"时刻"?

更新 我也按照其他问题的建议尝试了......

import * as moment from 'moment';
Run Code Online (Sandbox Code Playgroud)

但是我得到了以下结果:

ERROR in node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.
node_modules/angular-moment-timezone/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.
Run Code Online (Sandbox Code Playgroud)

Ale*_*sky 5

请尝试以下导入时刻:

import * as moment from 'moment';
Run Code Online (Sandbox Code Playgroud)

希望这有帮助!