Javascript 角度范围';t应用程序更新

Javascript 角度范围';t应用程序更新,javascript,angularjs,Javascript,Angularjs,我无法更新正在ng repeat中处理的范围变量 <div ng-controller="MapViewCtrl"> <a class="item item-avatar" ng-href="#/event/tabs/mapView" > <img src="img/location.jpg"/> <span class="input-label">Locat

我无法更新正在ng repeat中处理的范围变量

 <div ng-controller="MapViewCtrl">
            <a class="item item-avatar" ng-href="#/event/tabs/mapView" >
                <img src="img/location.jpg"/>
                <span class="input-label">Locations Of event</span>
                <div    ng-repeat="item in positions" style="font-size: 12">{{item.address}}</div>
            </a>
        </div>

我的控制器看起来像:

 $scope.closePage = function() {
        for (var i = 0; i < markers.length; i++) {
            var lng = markers[i].position.A;
            var lat = markers[i].position.k;
            var address = "";
            var latlng = new google.maps.LatLng(lat, lng);
            $scope.$apply( $scope.geocoder.geocode({'latLng': latlng},function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[0]) {
                        address =results[0].formatted_address;
                        var location ={
                            address: address
                        }
                        $scope.positions.push(location);
                    }
                }
            }));
        }
        $state.go ('eventmenu.createevent');
    };
$scope.closePage=函数(){
对于(var i=0;i

您对如何更新positions变量有什么建议吗?

您需要将包含代码的函数传递给,而不仅仅是代码:

$scope.geocoder.geocode({'latLng': latlng},function(results, status) {
    $scope.$apply(function(){
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {
                address =results[0].formatted_address;
                var location = {
                    address: address
                }
                $scope.positions.push(location);
            }
        }
    })
});
还要注意,apply是在来自地理编码器的回调中调用的。这告诉Angular它需要检查范围中的更改