簡體   English   中英

Angular配置ES6語法

[英]Angular configure es6 syntax

我試圖讓角谷歌地圖工作在我的ES6語法。 在es5中,它看起來像這樣:

.config(function(uiGmapGoogleMapApiProvider) {
    uiGmapGoogleMapApiProvider.configure({
    //    key: 'your api key',
    v: '3.20',
    libraries: 'weather,geometry,visualization'
});
})

在es6中,我這樣做:但是我得到“配置”不是一個函數。

export default function uiGmapGoogleMapApiProvider() {
uiGmapGoogleMapApiProvider.configure({
    //    key: 'your api key',
    v: '3.20',
    libraries: 'weather,geometry,visualization'
});
}

如何在es6中正確編寫? 謝謝!

您需要注入依賴性。

angular.module('yourApp')
    .config(mapConfig);

mapConfig.$inject = ['uiGmapGoogleMapApiProvider'];

function mapConfig(uiGmapGoogleMapApiProvider) {
    uiGmapGoogleMapApiProvider.configure({
        //    key: 'your api key',
        v: '3.20',
        libraries: 'weather,geometry,visualization'
    });
}

“使用” es6我認為您是指課程。 如果要使用類,請使用構造函數。

mapConfig.$inject = ['uiGmapGoogleMapApiProvider'];

export default class mapConfig {
    constructor(uiGmapGoogleMapApiProvider) {
        uiGmapGoogleMapApiProvider.configure({
            //    key: 'your api key',
            v: '3.20',
            libraries: 'weather,geometry,visualization'
        });
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM