ngIf 不更新变量

ngIf doesn't update with variable

我有一个非常简单的 ng-if 结构,使用两个 MD 按钮和一个 AngularJS 范围变量 isPlaying。但是,ng-if 似乎无法与变量一起使用。当我使用控制台工具单击按钮时,我可以看到变量在变化,但是 DOM 没有变化。奇怪的是,当我将鼠标悬停在其他 Angular 组件(例如主导航中的按钮)时,ng-if 似乎确实会触发。

HTML/MD/PHP:

<md-button class="md-icon-button" ng-if="!isPlaying" ng-click="play()" aria-label="Play">
    <md-icon md-svg-src="<?php echo get_stylesheet_directory_uri(); ?>/img/icon/ic_play_arrow_black_24px.svg"></md-icon>
</md-button>
<md-button class="md-icon-button" ng-if="isPlaying" ng-click="pause()" aria-label="Pause">
    <md-icon md-svg-src="<?php echo get_stylesheet_directory_uri(); ?>/img/icon/ic_pause_black_24px.svg"></md-icon>
</md-button>

JS:

$scope.play = function () {
    player.playVideo();
    $scope.isPlaying = true;
}

$scope.pause = function () {
    player.pauseVideo();
    $scope.isPlaying = false;
}

问题是由包含在超时块中的函数引起的。我用 $timeout 替换了 setTimeout 并且一切都开始正常工作:

$scope.isPlaying = false;
$scope.videoTime = 0;
function onPlayerStateChange() {
    console.log(player);
    if (player.getPlayerState() === 1)
        $scope.isPlaying = true;
    else
        $scope.isPlaying = false;
    $timeout(onPlayerStateChange, 500);
}