我正在尝试让 Angular google map 在我的 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 中正确编写它?谢谢!
最佳答案
您需要注入(inject)您的依赖项。
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'
});
}
}
关于javascript - Angular 配置 es6 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37396423/