$ http调用后角度视图不更新

时间:2016-03-23 20:00:32

标签: angularjs ionic-framework

我正在尝试从我的服务器获取堆栈列表并使用ng-repeat填充视图但由于某种原因,即使更新范围,视图也不会更新。这是我的代码

    $scope.my = {stacks : []};
    $http.post('https://myurl',{"action":"login"}).success(function (data, status, headers, config) {
    $scope.my.stacks = data.stacks;
    console.log($scope.my.stacks); //logs the correct value
    //$scope.$apply() // don't need to do it, tried but it raised the already running digest cycle error
}).error(function (data, status){
    alert(data)
});

这是我的HTML

        //{{stacks}} if I do this, the view updates OK, strange
        <ion-slide-box on-slide-changed="slideHasChanged($index)">
        <ion-slide ng-repeat="stack in my.stacks">
            <div class="list card">
                <div class="item item-avatar">
                    <img src="./img/ionic.png">
                    <h2>{{stack.stack_name}}</h2>
                    <p>{{stack.stack_description}}</p>
                </div>
                <div class="item item-image">
                    <img style="max-width:100%;height:auto" src="./img/Test_Icon.png">
                </div>
                <a class="item item-icon-left assertive" ng-click="chooseStack(stack)">
                    <i class="icon ion-social-buffer-outline"></i>
                    Go to Stack
                </a>
            </div>
        </ion-slide>
    </ion-slide-box>

此外,一旦我更改方向,视图就会更新。我做错了什么?

1 个答案:

答案 0 :(得分:2)

问题是Ionic幻灯片。您需要让它知道范围变量已按照here所述进行更新。