加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何使用ng2-datepicker for angular 2 app

发布时间:2020-12-17 17:08:04 所属栏目:安全 来源:网络整理
导读:我想在我的应用程序中包含ng2-datepicker模块.我尝试按照自述文件中的说法进行操作. npm install ng2-datepicker --save 修改systemjs.config.js文件到: .map { 'ng2-datepicker': 'npm:ng2-datepicker','moment': 'npm:moment/moment.js'} 'ng2-datepicker
我想在我的应用程序中包含ng2-datepicker模块.我尝试按照自述文件中的说法进行操作.

npm install ng2-datepicker --save

修改systemjs.config.js文件到:

.map {
 'ng2-datepicker': 'npm:ng2-datepicker','moment': 'npm:moment/moment.js'
}
  'ng2-datepicker': {
          format: 'register',defaultExtension: 'js'
      }

在index.html中添加以下行:

<script src="node_modules/moment/moment.js"></script>

在app.module.ts中添加了以下行

import { DatePicker } from 'ng2-datepicker/ng2-datepicker';
declarations: [ AppComponent,DatePicker]

加载应用程序时出现以下错误:

Error: ReferenceError: require is not defined
        at eval (http://localhost:3000/node_modules/ng2-datepicker/ng2-datepicker.js:2:24)
        at eval (http://localhost:3000/node_modules/ng2-datepicker/ng2-datepicker.js:7:3)
        at ZoneDelegate.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:203:28)     
           Evaluating http://localhost:3000/node_modules/ng2-datepicker/ng2-datepicker.js   
           Error loading http://localhost:3000/node_modules/ng2-datepicker/ng2-datepicker.js as "ng2-datepicker/ng2-datepicker" from http://localhost:3000/app/app.module.js

解决方法

我可能会使用不同的编译器.
但就我而言,这是我的地图定义:

var map = {
   ...
   'ng2-datepicker':               'app-ui/node_modules/ng2-datepicker','moment':                       'app-ui/node_modules/moment',... 
};

我正在使用system.js和映射没有moment.js为我做了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读