在material中的时间控件中,使用moment.js来更改本地日期格式时,出现如下错误:
1 |
"moment" has no exported member 'default' when importing the library. |
下面是我的代码:
1 2 3 4 5 6 |
import {Inject, Injectable, Optional} from '@angular/core'; import {DateAdapter, MAT_DATE_LOCALE, MatDateFormats} from '@angular/material'; import * as _moment from 'moment'; import {default as _rollupMoment, Moment} from 'moment'; const moment = _rollupMoment || _moment; |
解决方案:
在tsconfig.json文件中,添加
1 2 3 4 5 6 7 8 |
{ "compileOnSave": false, "compilerOptions": { .... "allowSyntheticDefaultImports": true }, } |