- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试将 moment.js 导入到我的 angular2 应用程序中。首先,我关注了这个 guide ,我找到了这个 answer但即使我尝试遵循建议的解决方案,我仍然无法导入 moment.js。该包存在,实际上我的 IDE(visual studio)能够毫无问题地找到 moment.d.ts 文件,但是当我使用 npm start 运行我的应用程序时,我在控制台中收到以下两个错误:
"NetworkError: 404 Not Found - http://localhost:3000/node_modules/moment/" /node_m...moment/ Error: patchProperty/desc.set/wrapFn@http://localhost:3000/node_modules/zone.js/dist/zone.js:769:27 Zonehttp://localhost:3000/node_modules/zone.js/dist/zone.js:356:24 Zonehttp://localhost:3000/node_modules/zone.js/dist/zone.js:256:29 ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:423:29
Error loading http://localhost:3000/node_modules/moment as "moment" from 'my file'
我试过用这种方式导入moment
import * as moment from 'moment'
并以这种方式
import * as moment from 'moment/moment.d'
但是没有,我仍然得到错误。我的SystemJs的map属性就是这个
var map = {
'app': 'app', // 'dist',
'@angular': 'node_modules/@angular',
'services': 'app/service',
'moment': 'node_modules/moment',//moment.js
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs'
};
如果我尝试使用类型进行安装,我会收到此错误:
Typings for "moment" already exist in "node_modules/moment/moment.d.ts". You should let TypeScript resolve the packaged typings and uninstall the copy installed by Typings
所以我卸载了它,然后重新输入命令,我得到了这个错误
typings ERR! message Unable to find "moment" ("npm") in the registry.
那么有没有办法摆脱这种困境呢?
最佳答案
首先,通过 npm 安装 moment 包:
npm install moment --save
其次更改您的 systemjs 配置(2 行):
(function (global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs',
'moment': 'node_modules/moment', <== add this line
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
'moment': { main: 'moment.js', defaultExtension: 'js' } <== add this line
};
然后就可以使用了:
import * as moment from 'moment';
类型将在 node_modules/moment/moment.d.ts
关于angular - 如何导入 moment.js angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38354048/
System.Math.MomentSkewKurtosis 声明为 procedure MomentSkewKurtosis(const Data: array of Double; var M1,
我尝试在应用程序中使用 moment.js 和 moment-timezone-with-data.js 来显示任何时区的日期。 我已将这两个 js 文件的 CDN 包含在我的 index.html
我对 Moment 函数的工作原理有点困惑(例如 startOf()、weekday() 等)。 我的问题是:如何从预定义的日期获取一周的开始? 考虑 9/21/16 上的这两个调用: moment(
阅读react-datepicker doc's后我尝试按照文档的说明更改日期选择器语言: Globally by calling moment.locale(lang) Picker-specifi
我有一个服务器生成的位置列表,采用国家/城市格式,即 Beijing London 我想使用 JS/Jquery 和 Moment Timezone 来执行此操作: 从每个项目中提取 data-tim
我有一个时刻对象和一个单独的时间字符串,如下所示: var selectedDay = moment(); var time = '6 PM'; 我想将两者结合起来,我无法从文档中弄清楚,就像这样。
我有一个时刻对象,我正在尝试添加几天。但是,它返回的结果是相同的 moment 对象。 但是,如果我只是尝试在当前日期执行此操作,则效果很好。 另外,请注意,我总是收到一个需要添加天数的时刻对象。 代
我有一个名为 date 的时刻对象: ( Tue Apr 09 2019 00:00:00 ...) 我想在最后一刻将其替换为同一天,如下所示: (Tue Apr 09 2019 23:59:59 .
目前我有一个输入字段,允许您通过输入两位数字来选择一个小时。例如,您可以选择 12 表示 12 小时。 有没有办法使用 MomentJS 将该数字转换为毫秒? 目前我必须做以下数学运算。我在 Mome
moment().format() 根据 moment().isValid() 创建无效日期 示例如下: > moment.version "2.14.1" > moment.locale() "fr
我正在使用 moment.js,但在测试 moment.js 库时,我继续收到错误。 var back30Days=moment().subtract(30, 'days').format("dddd
在使用 moment 构建 angular 8 项目时,我遇到了以下错误消息: ng build @myproject/common Error: Cannot call a namespace ('
我安装了 moment.js 库并准备稍微玩弄它,当我收到此错误时。我尝试了很多不同的东西,但没有任何效果。有任何想法吗? 我有一个文件夹,我已经将 moment.js 安装到(npm install
我有一个时间戳的初始值(在 User-1 的时区中创建),我正在从 firebase 的 firestore 中检索。其格式为 Unix 纪元的 UTC 秒数。 我的目标是获取初始时间戳值,并将其转换
有一个从元素的 innerText 设置的 startTime。然后使用 moment(startTime) 将该字符串转换为 Moment.js 对象。然后如何将其转换为以分钟为单位的数字值? Ja
我使用 moment.js 创建了一个 js 脚本,我想通过 cron 作业复制它。因此,它将使用 PHP。 所以,我搜索了 moment.js 的等价物,我找到了这个 https://github.
我得到一个文本值,它的格式如下:“9/19/2018 10:00 AM”。您将如何使用 moment.js 或仅使用 javascript 将其转换为纪元时间戳? 示例: console.log(mo
$> moment.version '2.18.1' $> moment('Mon, 02 Jan 2017 06:00:00 -0800').format() '2017-01-02T01:00:0
我有一个jsfiddle here 。 它是空白的,因为我想做的事情不起作用...... 我已经调用了适当的外部脚本。 我正在尝试将这个令人难以置信的库实现到我的网站中,但我不确定我做错了什么。 最终
我有 moment 对象,我想将其转换为格式为 dd.mm.yy 的字符串。使用 moment.js 执行此操作的最佳方法是什么? 我尝试了toString函数,但它返回的日期格式为Wed Mar 2
我是一名优秀的程序员,十分优秀!