我需要通过此 - > https://github.com/vimalavinisha/angular2-google-chart
将谷歌图表添加到我的项目中我遵循了每一步。但是我从SystemJs得到了这个错误。我找到了一些答案(2-3个月大),但它们对我不起作用。(Angular 2)
这是我的package.json
{
"name": "angular-quickstart",
"version": "1.0.0",
"scripts": {
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/angular/angular.io/blob/master/LICENSE"
}
],
"dependencies": {
"@angular/common": "~2.1.0",
"@angular/compiler": "~2.1.0",
"@angular/core": "~2.1.0",
"@angular/forms": "~2.1.0",
"@angular/http": "~2.1.1",
"@angular/platform-browser": "~2.1.0",
"@angular/platform-browser-dynamic": "~2.1.0",
"@angular/router": "~3.1.0",
"@angular/upgrade": "~2.1.0",
"angular-in-memory-web-api": "~0.1.5",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.3",
"typings":"^1.4.0"
}
}
systemjs.config.js ----
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular2-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
});
})(this);
tsConfig.json ---
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
最后是app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { GoogleChart } from 'angular2-google-chart/directives/angular2-google-chart.directive';
@NgModule({
imports: [ BrowserModule ,GoogleChart],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
这是我得到的错误 - >错误加载http://localhost:3000/angular2-google-chart/directives/angular2-google-chart.directive为" angular2-google-chart / directives / angular2-google-chart.directive
我找不到任何有效的答案,我已经失去了很多时间来解决这个错误。
答案 0 :(得分:0)
当我查看您分享的示例systemjs.config.js时,它仍然缺少directives
和map
中的packages
属性。
以下是github文件https://github.com/vimalavinisha/angular2-google-chart/blob/master/systemjs.config.js
的外观 var map = {
...
'directives' : 'directives/'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
...
'directives':{ defaultExtension: 'js' }
};
答案 1 :(得分:0)
我自己解决了。我创建了自己的指令,并从angular2-google-chart.diretive.ts文件中复制粘贴源代码。它对我来说是唯一有效的方式。