【发布时间】:2016-08-10 04:20:03
【问题描述】:
我是 angularjs 的新手(特别是 angular js2)。
我对 SystemJS 导入/配置感到困惑。
我的应用程序 (angularjs2) 可以正常工作。我正在使用 Visual Studio 开发它。
我已经设置了在 node_modules 中加载我必要的东西的 package.json。 就我而言,我想使用 chart.js
来自 package.json 文件的 sn-p
"dependencies": {
"angular2": "2.0.0-beta.15",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"systemjs": "^0.19.26",
"zone.js": "0.6.11",
"bootstrap": "3.3.6",
"jquery": "2.2.3",
"font-awesome": "4.5.0",
"toastr": "2.1.2",
"chart.js": "2.0.2"
},
在我的 Index.html 中,我有以下内容:
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/main')
.then(null, console.error.bind(console));
$(document).ready(function () {
window.toastr = toastr;
setTimeout(function () {
toastr.options = {
closeButton: true,
progressBar: true,
showMethod: 'slideDown',
timeOut: 2500
};
toastr.success('Welcome to the APP');
}, 1300);
});
</script>
Chart JS如何导入:
<!-- ChartJS-->
<!--version1: OLD ChartJS importing WORKS ok-->
<!--<script src="scripts/plugins/chartJs/Chart.min.js"></script>-->
<!--version2: This kind of importing does not work-->
<script src="node_modules/chart.js/dist/Chart.min.js"></script>
注意:
我有一个 toastr,它也是通过这种方式从 node_modules 导入的:
<!-- Toastr -->
<script src="node_modules/toastr/build/toastr.min.js"></script>
但它工作正常。
node_modules 文件夹不包含在我的解决方案中
我将在组件中使用它(稍后在单独的指令中 - 根据最佳方法)
在那一行
var myNewChart = new Chart(ctx).Line(lineData, options);
它在抱怨:
ReferenceError: Chart is not defined
at DashboardComponent.execute.DashboardComponent.createLinearChart
【问题讨论】:
标签: visual-studio angular node-modules systemjs