【问题标题】:Angular UI - angular-google-maps. Is It possible to configure uiGmapGoogleMapApiProvider.configure(options) dinamically?Angular UI - 角谷歌地图。是否可以动态配置 uiGmapGoogleMapApiProvider.configure(options)?
【发布时间】:2016-11-30 09:40:47
【问题描述】:

是否可以将选项从 promise (ex. $http.get(...)) 动态插入到

.config(function(uiGmapGoogleMapApiProvider) {
    uiGmapGoogleMapApiProvider.configure(<object from $http>);
})

angular-ui angular-google-maps 指令? 如果不能,您能建议任何替代方法吗?

谢谢 问候

【问题讨论】:

    标签: angularjs google-maps google-maps-api-3 angular-ui angular-promise


    【解决方案1】:

    不,像$http 这样的服务不能注入到提供者配置部分。相反,您可以考虑以下解决方案:

    • 加载配置数据
    • 加载数据后,通过uiGmapGoogleMapApi provider 配置 Google 地图加载器
    • 手动引导应用程序

    示例

    angular.element(document).ready(function () {
      $.getJSON('settings.json')
        .then(function (configData) {
          angular.module('myApp')
          .config(['uiGmapGoogleMapApiProvider', function (uiGmapGoogleMapApiProvider) {
            uiGmapGoogleMapApiProvider.configure(configData);
           }]);
          angular.bootstrap('#myApp', ['myApp']);
        });
    });
    

    Demo: plunker

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 2011-01-03
      • 1970-01-01
      • 2014-04-16
      • 2014-07-10
      • 1970-01-01
      • 2011-04-15
      相关资源
      最近更新 更多