Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger $digest loop when use finishCallback #273

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/js/_timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var timerModule = angular.module('timer', [])
monthsS: '=?',
yearsS: '=?'
},
controller: ['$scope', '$element', '$attrs', '$timeout', 'I18nService', '$interpolate', 'progressBarService', function ($scope, $element, $attrs, $timeout, I18nService, $interpolate, progressBarService) {
controller: ['$scope', '$element', '$attrs', '$timeout', 'I18nService', '$interpolate', 'progressBarService', '$rootScope', function ($scope, $element, $attrs, $timeout, I18nService, $interpolate, progressBarService, $rootScope) {

// Checking for trim function since IE8 doesn't have it
// If not a function, create tirm with RegEx to mimic native trim
Expand Down Expand Up @@ -298,7 +298,11 @@ var timerModule = angular.module('timer', [])
$scope.millis = 0;
calculateTimeUnits();
if($scope.finishCallback) {
$scope.$eval($scope.finishCallback);
if ($rootScope.$$phase) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to avoid this undocumented API usage?

Copy link
Author

@hjzheng hjzheng Aug 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, As far as I know It is a only way to detect whether the $digest loop is running.

$scope.$evalAsync($scope.finishCallback);
} else {
$scope.$apply($scope.finishCallback);
}
}
return;
}
Expand All @@ -318,7 +322,11 @@ var timerModule = angular.module('timer', [])
else if ($scope.countdown <= 0) {
$scope.stop();
if($scope.finishCallback) {
$scope.$eval($scope.finishCallback);
if ($rootScope.$$phase) {
$scope.$evalAsync($scope.finishCallback);
} else {
$scope.$apply($scope.finishCallback);
}
}
}

Expand Down
24 changes: 15 additions & 9 deletions dist/angular-timer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/**
* angular-timer - v1.3.4 - 2016-05-01 9:52 PM
* https://github.com/siddii/angular-timer
* angular-timer - v1.3.5 - 2016-08-16 4:33 PM
* https://github.com/june07/angular-timer
*
* Copyright (c) 2016 Siddique Hameed
* Licensed MIT <https://github.com/siddii/angular-timer/blob/master/LICENSE.txt>
* Copyright (c) 2016 Adrian Wardell
* Licensed MIT <https://github.com/june07/angular-timer/blob/master/LICENSE.txt>
*/
var humanizeDuration = require("humanize-duration");
var moment = require("moment");
var timerModule = angular.module('timer', [])
.directive('timer', ['$compile', function ($compile) {
return {
Expand Down Expand Up @@ -35,7 +33,7 @@ var timerModule = angular.module('timer', [])
monthsS: '=?',
yearsS: '=?'
},
controller: ['$scope', '$element', '$attrs', '$timeout', 'I18nService', '$interpolate', 'progressBarService', function ($scope, $element, $attrs, $timeout, I18nService, $interpolate, progressBarService) {
controller: ['$scope', '$element', '$attrs', '$timeout', 'I18nService', '$interpolate', 'progressBarService', '$rootScope', function ($scope, $element, $attrs, $timeout, I18nService, $interpolate, progressBarService, $rootScope) {

// Checking for trim function since IE8 doesn't have it
// If not a function, create tirm with RegEx to mimic native trim
Expand Down Expand Up @@ -307,7 +305,11 @@ var timerModule = angular.module('timer', [])
$scope.millis = 0;
calculateTimeUnits();
if($scope.finishCallback) {
$scope.$eval($scope.finishCallback);
if ($rootScope.$$phase) {
$scope.$evalAsync($scope.finishCallback);
} else {
$scope.$apply($scope.finishCallback);
}
}
return;
}
Expand All @@ -327,7 +329,11 @@ var timerModule = angular.module('timer', [])
else if ($scope.countdown <= 0) {
$scope.stop();
if($scope.finishCallback) {
$scope.$eval($scope.finishCallback);
if ($rootScope.$$phase) {
$scope.$evalAsync($scope.finishCallback);
} else {
$scope.$apply($scope.finishCallback);
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions dist/angular-timer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading