2016-05-29 59 views
2

有谁知道如何将谷歌地图添加到角2应用程序?有谁知道如何将谷歌地图添加到角2应用程序?

我目前链接到它在我的index.html页,像这样:

<script src="node_modules/angular2-google-maps/bundles/angular2-google-maps.js"></script> 

但在我的角度2组件使用它时,我得到这个控制台错误:

system.src。 JS:1061 GET http://localhost:3000/angular2-google-maps/core 404(未找到)

这是我的控制台的屏幕截图:

enter image description here

系统配置:

System.config({ 
    packages: {  
    app: { 
     format: 'register', 
     defaultExtension: 'js' 
    }, 
    'angular2-google-maps': { defaultExtension: 'js' } 
    } 
}); 
System.import('app/boot') 
     .then(null, console.error.bind(console)); 
+0

你配置了systemjs吗? – dfsq

+0

你好,我已经在 – AngularM

回答

1

我认为你忘了把它添加到您的system.js配置:

var packages = { 
    ... 
    'angular2-google-maps':  { defaultExtension: 'js' } <== this line 
    }; 

参见http://angular-maps.com/docs/getting-started.html#angular2-google-maps-setup(部分更新systemjs.config.js )

它仅适用于angular2^rc.X

+0

以下添加了我目前的步骤我刚刚添加了这个:'angular2-google-maps':{defaultExtension:'js'} 但是现在我得到这个控制台错误:“system.src.js :1061 GET http:// localhost:3000/@ angular/core 404(Not Found)“ – AngularM

+0

我将它像这样导入到我的index.html中: AngularM

+0

这是我如何将它导入到我的boot.ts文件中: 从'angular2-google-maps/core'导入{ANGULAR2_GOOGLE_MAPS_PROVIDERS}; – AngularM

8

经过漫长的研究,我发现了以下解决方案,

一旦我们安装了Angular2-google-maps,我们忘了将js文件映射到我们的配置中。

打开你的systemjs.config.js

并添加'angular2-google-maps/core': 'npm:angular2-google-maps/core/core.umd.js'在你的地图目录。

我的代码:

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', 
    'angular2-google-maps/core': 'npm:angular2-google-maps/core/core.umd.js' 
    }, 

它可以帮助别人。 谢谢!

+0

我的项目,我有以下配置来解决这个问题:'angular2 - 谷歌 - 地图/芯 ':' node_modules/angular2 - 谷歌 - 地图/核心/ core.umd。 JS',' –

相关问题