2016-05-29 44 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',' –

相關問題