无法从谷歌地图自定义控件打开离子模态

时间:2016-04-23 21:32:22

标签: javascript angularjs google-maps ionic-framework

我有一个带有自定义控件的谷歌地图,我希望它在点击时打开离子模态。我有另一个控件,清除地图上的标记,它工作正常。

如果我将import re import inspect def describe_function(function): """Return a function's argspec using its docstring If usages discovered in the docstring conflict, or default values could not be resolved, a generic argspec of *arg and **kwargs is returned instead.""" s = function.__doc__ if s is not None: usages = [] p = r'([\w\d]*[^\(])\( ?([^\)]*)' for func, usage in re.findall(p, s): if func == function.__name__: usages.append(usage) longest = max(usages, key=lambda s: len(s)) usages.remove(longest) for u in usages: if u not in longest: # the given usages weren't subsets of a larger usage. return inspect.ArgSpec([], 'args', 'kwargs', None) else: args = [] varargs = None keywords = None defaults = [] matchedargs = re.findall(r'( ?[^\[,\]]*) ?,? ?', longest) for a in [a for a in matchedargs if len(a)!=0]: if '=' in a: name, default = a.split('=') args.append(name) p = re.compile(r"<\w* '(.*)'>") m = p.match(default) try: if m: d = m.groups()[0] # if the default is a class default = import_item(d) else: defaults.append(eval(default)) except: # couldn't resolve a default value return inspect.ArgSpec([], 'args', 'kwargs', None) elif '**' in a: keywords = a.replace('**', '') elif '*' in a: varargs = a.replace('*', '') else: args.append(a) return inspect.ArgSpec(args, varargs, keywords, defaults) # taken from traitlet.utils.importstring def import_item(name): """Import and return ``bar`` given the string ``foo.bar``. Calling ``bar = import_item("foo.bar")`` is the functional equivalent of executing the code ``from foo import bar``. Parameters ---------- name : string The fully qualified name of the module/package being imported. Returns ------- mod : module object The module that was imported. """ if not isinstance(name, string_types): raise TypeError("import_item accepts strings, not '%s'." % type(name)) name = cast_bytes_py2(name) parts = name.rsplit('.', 1) if len(parts) == 2: # called with 'foo.bar....' package, obj = parts module = __import__(package, fromlist=[obj]) try: pak = getattr(module, obj) except AttributeError: raise ImportError('No module named %s' % obj) return pak else: # called with un-dotted string return __import__(parts[0]) 作为按钮的功能,我会得到&#34;无法读取财产&#39; $$已销毁&#39;未定义&#34;当我点击它时。

如果我在页面加载时打开modal.show模式,我不想要,然后单击按钮时再次打开。

控制器

modal.show()

从工厂

.controller('MapCtrl', function(mapServ, mapFact, $ionicModal, $scope){
  var vm = this;

  var gmap = mapServ.init();
  var markers = mapServ;

  // Create modal and Custom Map Controls
  $ionicModal.fromTemplateUrl('templates/modal.html', {
    scope: $scope
  }).then(function(modal) {
    vm.modal = modal;

    var controlContainer = document.createElement('div');
    var clearControl = new mapFact.Control(controlContainer, 'Clear Map', mapFact.clearMap);
    var locControl = new mapFact.Control(controlContainer, 'Locations', vm.modal.show());

    controlContainer.index = 1;
    gmap.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlContainer);
  });

   // Create Markers
   mapFact.markers($rootScope.rests, gmap).then(function(results) {
   mapServ.markers = results;
   vm.markers = mapServ.markers;
 });
});

1 个答案:

答案 0 :(得分:0)

Ionic - Javascript Modal中给出了两种在Ionic中实现模态的方法。

您可以添加单独的模板,也可以将其添加到常规HTML文件的顶部,在脚本标记内。首先,您需要将模态连接到控制器,然后创建模态。之后,创建将被触发的打开功能。最后,创建一个按钮以触发modal.show()打开模态。

示例HTML代码:

<button class = "button" ng-click = "openModal()"></button>