当参数更新为false时,ngShow不隐藏视图

时间:2017-06-03 18:11:41

标签: javascript angularjs

我试图在3秒后使用$ timeout隐藏我视图的一部分,但是出于一些奇怪的原因,尽管$ scope值正在更新,但这并没有发生。

$scope.failed = true;
$scope.des = res.data.description;
$timeout(function(){
   $scope.failed = false;
   $scope.loading = false;
   $scope.des = null;
   console.log($scope.failed);
}, 2000);

模板

<div class="done failed" ng-show="failed">
   <i class="material-icons">error_outline</i>
   <p>{{des}}</p>
</div>

1 个答案:

答案 0 :(得分:1)

试试这个:

$scope.status = {failed: true};
$scope.des = res.data.description;
$timeout(function(){
   $scope.status.failed = false;
   $scope.loading = false;
   $scope.des = null;
   console.log($scope.status.failed);
}, 2000);

模板

<div class="done failed" ng-show="status.failed">
   <i class="material-icons">error_outline</i>
   <p>{{des}}</p>
</div>