Javascript 使用ng bind时更新指令中的数据

Javascript 使用ng bind时更新指令中的数据,javascript,angularjs,Javascript,Angularjs,我有一个场景,每个候选人都有一个秒表。 候选人信息在ng repeat中,我在stop watch指令控制器中传递doi(面试日期)值,如下所示 angular.module('hrPortalApp') .directive('stopWatch', function() { debugger; return { restrict: 'A', replace: false, scope: { name: "

我有一个场景,每个候选人都有一个秒表。
候选人信息在
ng repeat
中,我在
stop watch
指令控制器中传递doi(面试日期)值,如下所示

angular.module('hrPortalApp')
.directive('stopWatch', function() {
    debugger;
    return {
        restrict: 'A',
        replace: false,
        scope: {
            name: "=",
            time: "=",
            timeOfInterview: "="
        },
        controller: function($scope) {
            debugger;
            $scope.getTimeRemaining = function(endtime) {
                debugger;
                $scope.t[$scope.name].total = Date.parse(endtime) - Date.parse(new Date());
                $scope.t[$scope.name].seconds = Math.floor(($scope.t[$scope.name].total / 1000) % 60);
                $scope.t[$scope.name].minutes = Math.floor(($scope.t[$scope.name].total / 1000 / 60) % 60);
                $scope.t[$scope.name].hours = Math.floor(($scope.t[$scope.name].total / (1000 * 60 * 60)) % 24);
                $scope.t[$scope.name].days = Math.floor($scope.t[$scope.name].total / (1000 * 60 * 60 * 24));
            }

            $scope.initializeClock = function(endtime) {
                debugger;
                $scope.t = {};
                $scope.t[$scope.name] = {};
                $scope.updateClock = function() {
                    debugger;
                    $scope.getTimeRemaining(endtime);
                    $scope.t[$scope.name].hours = ('0' + $scope.t[$scope.name].hours).slice(-2);
                    $scope.t[$scope.name].minutes = ('0' + $scope.t[$scope.name].minutes).slice(-2);
                    $scope.t[$scope.name].seconds = ('0' + $scope.t[$scope.name].seconds).slice(-2);

                    if ($scope.t[$scope.name].total <= 0) {
                        clearInterval($scope.timeinterval);
                    }
                }

                $scope.updateClock();
                $scope.timeinterval = setInterval($scope.updateClock, 1000);
            }


            $scope.initializeClock($scope.timeOfInterview);
        },
        templateUrl: './views/stopWatchView.html'
    };

});

我面临的问题是计时器计数器不是每次都更新


任何帮助都将不胜感激。

我认为您的问题是因为您使用了
窗口。setInterval
而不是
因此,摘要周期不会运行,因此不会注意到您的更改

试着重写这行

$scope.timeinterval = setInterval($scope.updateClock, 1000);
要使用angular的$interval,例如

$scope.timeinterval= $interval($scope.updateClock, 1000)

你注射了吗?嘿@DAXaholic好像起作用了,我忘了注射了。谢谢
$scope.timeinterval= $interval($scope.updateClock, 1000)