search

Home  >  Q&A  >  body text

angular.js - angular-timer 插件的finish-callback()不刷新视图

<p ng-show="smsSent">
<timer interval="1000" countdown="60" end-time="0" finish-callback="smsSent=!smsSent">{{seconds}}</timer>
</p>

我想在这个timer倒数计时结束后,调用finish-callback,然后smsSent的值就取反了,因此<p ng-show="smsSent">这个p会隐藏起来,问题是....现在倒数计时到0了之后,我观察到smsSent的值确实变了,但是<p ng-show="smsSent">这个p并不隐藏,意味着没有刷新试图,求助,我改如何做才能隐藏那个p

滿天的星座滿天的星座2744 days ago876

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-15 17:07:21

    Thank you for the invitation. Can you provide how to write the timer command, or give a link to jsbin or jsfiddle.net to reproduce it. The information currently provided is that the value has been changed, but the Dom is not rendered. I think you can trigger the dirty check in finish-callback $apply 或者 $evalAsync.

    ------------------ dividing line ----------------

    Find the plug-in you mentioned https://github.com/siddii/ang... , I will make a pull request soon, so you don’t need to actively trigger it in finish-callback $apply.

    ------------------Separating line----------------
    https://github.com/siddii/ang. ..

    The request has been pulled, mainly the following paragraph. When $scope.finishCallback is called, the dirty check loop is actively triggered

                 if($scope.finishCallback) {
     -              $scope.$eval($scope.finishCallback);
     +              if ($rootScope.$$phase) {
     +                $scope.$evalAsync($scope.finishCallback);
     +              } else {
     +                $scope.$apply($scope.finishCallback);
     +              }
                  }

    reply
    0
  • Cancelreply