Angular配置es6语法 [英] Angular configure es6 syntax

查看:207
本文介绍了Angular配置es6语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让角度谷歌地图工作在我的es6语法。
在es5它看起来像这样:

Im trying to get angular google maps to work in my es6 syntax. In es5 it looks like this:

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

在es6中,我做到了这一点:但是我觉得configure不是一个函数。 p>

In es6 i did this: But i get that "configure" is not a function.

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

我将如何在es6中正确写入?谢谢!

How would i write it properly in es6? Thanks!

推荐答案

你需要注意你的依赖。

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我认为你的意思是类。如果你想使用一个类,请使用构造函数。

To 'use' es6 i think you mean classes. If you wanted to use a class, use the constructor.

mapConfig.$inject = ['uiGmapGoogleMapApiProvider'];

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

这篇关于Angular配置es6语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆