0

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'
});
})

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'
});
}

How would i write it properly in es6? Thanks!

1 Answer 1

1

You need to inject your dependency.

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

mapConfig.$inject = ['uiGmapGoogleMapApiProvider'];

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

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'
        });
    }
}
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you. But what if i already have one config? The route provider in this case.
you can invoke .config in multiple places. using component based design each component should configure itself.
hm, did not work. it says that $inject is undefined.
the projects is set up sp that i have one file that imports all controllers ans services. that works good. but i cant get the config to work for the map. Here is an example of how i have structured it: jsfiddle.net/c1kos1g5/1 the mapcontroller works and logs "hello".
Any ideas on this @d3l33t
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.