我正在尝试让angular google地图在我的es6语法中工作。在es5中,它看起来像这样:
.config(function(uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
// key: 'your api key',
v: '3.20',
libraries: 'weather,geometry,visualization'
});
})在es6中,我这样做了:但是我知道"configure“不是一个函数。
export default function uiGmapGoogleMapApiProvider() {
uiGmapGoogleMapApiProvider.configure({
// key: 'your api key',
v: '3.20',
libraries: 'weather,geometry,visualization'
});
}我如何在es6中正确地编写它?谢谢!
发布于 2016-05-24 00:59:54
你需要注入你的依赖项。
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'
});
}
}https://stackoverflow.com/questions/37396423
复制相似问题