ng-hide类甚至与ng-show的真值保持一致

时间:2016-08-29 20:11:03

标签: angularjs ionic-framework

在我的代码中,ng-hide值在控制器中的某个位置变为true(在解析异步函数之后)但是ng-hide类保留在元素上...

             <div class="averageRatingContainer" ng-show="data.showStars">
                    <div class="star-ratings-css">
                        <div class="star-ratings-css-top" ng-style="{width: data.avgRating + '%'}">
                            <span><i class="ion-ios-star"></i></span>
                            <span><i class="ion-ios-star"></i></span>
                            <span><i class="ion-ios-star"></i></span>
                            <span><i class="ion-ios-star"></i></span>
                            <span><i class="ion-ios-star"></i></span>
                        </div>
                        <div class="star-ratings-css-bottom">
                            <span><i class="ion-ios-star"></i></span>
                            <span><i class="ion-ios-star"></i></span>
                            <span><i class="ion-ios-star"></i></span>
                            <span><i class="ion-ios-star"></i></span>
                            <span><i class="ion-ios-star"></i></span>
                        </div>
                    </div>

在控制器中:

 $scope.data.showStars = false;

$scope.getAvgRating = function() {
            pouchDBservice.getAverageRating($scope.prodata[$scope.data.computed.proId].modelStrict, function (result) {  //...ASYNC
                if (!result) {
                    console.log('...shit !');
                    $scope.data.avgRating = 0;
                    $scope.data.numberOfRatings = 0;
                    $scope.data.showStars = true;
                    console.log("getting avg rating done")            
                } else {
                    $scope.data.averageRating = result.averageRating;
                    $scope.data.numberOfRatings = result.numberOfRatings;
                    console.log('average rating: ', $scope.data.averageRating, ', number of ratings: ', $scope.data.numberOfRatings  );
                    $scope.data.avgRating = $scope.data.averageRating*100/5;
                    $scope.data.showStars = true;
                    console.log("getting avg rating done")
                }
            } );
        }

所以当函数完成后,$scope.data.showStars变为true,ng-hide类应该消失!

有什么想法吗?

由于

0 个答案:

没有答案