Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度谷歌地图信息窗口HTML_Javascript_Angularjs_Google Maps_Angularjs Directive - Fatal编程技术网

Javascript 角度谷歌地图信息窗口HTML

Javascript 角度谷歌地图信息窗口HTML,javascript,angularjs,google-maps,angularjs-directive,Javascript,Angularjs,Google Maps,Angularjs Directive,我已经将angular google maps()与我的ionic framework应用程序集成。。一切都很顺利,但我在infoWindow方面遇到了一些问题。。窗口显示正确,但InfoWidNow按钮内的ng click事件对我不起作用 这是我在控制器中的代码 $scope.confirmCode = function() { console.log("sdf"); if(confirm("Are you sure?")) { Category.getCode(wind

我已经将angular google maps()与我的ionic framework应用程序集成。。一切都很顺利,但我在infoWindow方面遇到了一些问题。。窗口显示正确,但InfoWidNow按钮内的ng click事件对我不起作用

这是我在控制器中的代码

$scope.confirmCode = function() {
  console.log("sdf");
  if(confirm("Are you sure?"))
  {
    Category.getCode(window.localStorage.getItem('user_place'), 0,     $stateParams.position_id, $scope.point_id, $scope.currentUser.id, function(data) {
      $scope.code = data.data[0];
      $scope.pointsModal.show();
    });
  }
};
这就是观点

<div class="map-show col">
      <google-map draggable="true" center="map.center" zoom="map.zoom">
          <markers models="locations" coords="'self'" icon="'icon'" click="'onClick'">
            <windows show="show">
              <div ng-non-bindable>{{heading}}<br/>{{address}}<br/><button ng-click="confirmCode()">Redeam</button></div>
            </windows>              
          </markers>
      </google-map>
    </div>

{{heading}}
{{address}
Redeam

我想我遗漏了一些与AngularJS的$compile相关的东西,但作为一名新手,我不确定如何使用它。

据我所知,ng non bindable将导致angular忽略dom结构下的所有后续指令调用。在这种情况下,它将导致忽略ng对按钮的单击(该按钮将继承不可绑定的内容),您使用该命令(我本人从未使用过该指令)有什么原因吗


参考资料:

经过数小时的搜索、点击和试用,我终于找到了解决方案。下面的帖子帮了很多忙,但是它

实际上,问题是infoWindow充当子控制器,而我的fuction$scope.confirmCode()是其父控制器的一部分。所以我做了两件事

  • 在infoWindow中使用ng斗篷
  • 使用
    ng单击=“$parent.$parent.$parent.$parent.confirmCode()”
  • 这是更新后的代码

    <div class="map-show col">
          <google-map draggable="true" center="map.center" zoom="map.zoom">
              <markers models="locations" coords="self" icon="icon" click="onClick">
                <windows show="'show'" ng-cloak>
                  <div>{{heading}}<br/>{{address}}<br/><a href="" ng-click="$parent.$parent.$parent.confirmCode()">Redeam</a></div>
                </windows>              
              </markers>
          </google-map>
        </div>
    
    
    {{heading}}
    {{address}}

    这是不可绑定的,意味着您必须将代码从内联模板中取出,放在它们自己的模板中,并将它们包含在templateUrl中,使用templateParameters选项注入对象,并向模板添加新的控制器

    看法


    我已经删除了ng non bindable,但仍然不起作用:(我猜它永远不会到达console.log?window指令是否有onClick侦听器可能阻止了单击?可以尝试指针事件:如果是这样的话,它上没有指针事件?此外,Ionic没有内置任何类型的单击侦听器?(我没有使用它)
     <windows show="show" templateUrl="'abspath/to/yourTemplate.html'" templateParameter="yourDataObject">
     </windows>  
    
    <div ng-controller="yourTemplateController">{{heading}}<br/>{{address}}<br/><button ng-click="confirmCode()">Redeem</button></div>
    
    angular.module('yourApp').controller('yourTemplateController', function ($scope) {
        $scope.confirmCode = function() {
          console.log("sdf");
          if(confirm("Are you sure?"))
          {
            Category.getCode(window.localStorage.getItem('user_place'), 0,     $stateParams.position_id, $scope.point_id, $scope.currentUser.id, function(data) {
              $scope.code = data.data[0];
              $scope.pointsModal.show();
            });
          }
        };
    });