【问题标题】:Importing moment.js导入 moment.js
【发布时间】:2017-06-12 00:30:38
【问题描述】:

我正在关注example 如何在 Ionic 2 RC5 中导入和使用时刻。

但它找不到文件。我的改进是在 src/index.html:

    <!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8">
  <title>Ionic App</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">

  <link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
  <link rel="manifest" href="manifest.json">
  <meta name="theme-color" content="#4e8ef7">

  <!-- cordova.js required for cordova apps -->
  <script src="cordova.js"></script>


  <!-- un-comment this code to enable service worker
  <script>
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js')
        .then(() => console.log('service worker installed'))
        .catch(err => console.log('Error', err));
    }
  </script>-->

  <link href="build/main.css" rel="stylesheet">

</head>
<body>

  <!-- Ionic's root component and where the app will load -->
  <ion-app></ion-app>

  <!-- The polyfills js is generated during the build process -->
  <script src="build/polyfills.js"></script>

  <!-- The bundle js is generated during the build process -->
  <script src="build/main.js"></script>
  <script src="node_modules/moment/moment.js" />

</body>
</html>

【问题讨论】:

  • 如果你想将它作为脚本添加到索引中(不建议)你需要再上一层../node_modules/moment/moment.js

标签: ionic2 angular-moment


【解决方案1】:

根据this链接在ionic2上使用momentjs:

1-npm install moment --save

2- 在您的 .ts 文件中:

import * as moment from 'moment';

例如:

ngOnInit() {
   let now = moment().format('LLLL');
   console.log(now);
}

【讨论】:

    猜你喜欢
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2023-01-18
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多