2016-12-01 80 views
0

我的要求是当我点击谷歌地图上的某些标记时,地点必须在引导列表中更新。但是,当我点击阵列更新,但列表不会在bootstrap更新。当我使用infowindow一切正常。地图标记和引导列表

HTML

<div class="panel-body"> 
    <ul style="padding-left:0px;"> 
     <li class="list-group-item list-group-item-info" ng-repeat="x in routesub" style="font-size:smaller;"> 
      <span class="badge" ng-click="delloc(x)">x</span> 
       {{x}} 
     </li> 
    </ul> 
    <button class="btn btn-danger btn-sm" ng-click="subsearch()">SUBSCRIBE</button> 
</div> 

app.js

google.maps.event.addListener(marker, 'click', (function (marker, i) { 
    return function() { 

        // var content1 = "<div><h6><font color='black'>" + locations[i].Name + "</font></h6><input type = 'button' class = 'btn btn-success btn-sm' value = 'Select' ng-click = 'SubLoc();' /></div>"; 
        //var content = $compile(content1)($scope); 
        //$scope.infowindow.setContent(content[0]); 
        //$scope.infowindow.open($scope.map, marker); 
        $scope.SubLoc = function() { 
         if ($scope.routesub.indexOf(locations[i].Name) == -1) { 
          $scope.routesub.push(locations[i].Name); 
          $scope.routeidsub1.push(locations[i].LocationId); 
          marker.setIcon(icon_sel); 
          // $scope.infowindow.close(); 
         } 
         else { 
          //$scope.infowindow.close(); 
         } 
        } 
        $scope.SubLoc(); 

       } 
      })(marker, i)); 

当我注释掉那些评论零部件和使用信息窗口一切perfecftly制定。当我点击标记时发表评论时,数据存储在$scope.routesub中,但在html中不可见。帮助我

回答

0

由于您在谷歌事件侦听器的“角度世界”之外,您有角度地告诉它必须启动一个消化周期来刷新它的界限值。

包裹要更新到像这样的$apply函数的值:

$scope.$apply(function(){ 
    $scope.routesub.push(locations[i].Name); 
}); 

另外,您也可以使用$timeout(我的首选方法),因为它不会产生“消化已在运行”错误:

$timeout(function(){ 
    $scope.routesub.push(locations[i].Name); 
}); 
+0

谢谢Danscho。现在它工作正常 – Alan