如何使用ng2-datepicker for angular 2 app

前端之家收集整理的这篇文章主要介绍了如何使用ng2-datepicker for angular 2 app前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我的应用程序中包含ng2-datepicker模块.我尝试按照自述文件中的说法进行操作.

@H_403_8@

@H_403_8@

npm install ng2-datepicker --save

修改systemjs.config.js文件到:@H_403_8@

@H_403_8@

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

在index.html中添加以下行:@H_403_8@

@H_403_8@

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

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

@H_403_8@

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

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

@H_403_8@

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

解决方法

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

@H_403_8@

@H_403_8@

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

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

猜你在找的Angularjs相关文章