Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.

Commit b55077e

Browse files
committed
Merge pull request #66 from masimakopoulos/master
make sure all watches are cleared
2 parents 9fc801d + 82aac83 commit b55077e

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

build/angular-intro.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-intro.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
link: function(scope, element, attrs) {
3535

3636
var intro;
37+
var refreshWatch;
38+
var navigationWatch;
3739

3840
scope.ngIntroMethod = function(step) {
3941

4042

41-
var navigationWatch = scope.$on('$locationChangeStart', function(){
43+
navigationWatch = scope.$on('$locationChangeStart', function(){
4244
intro.exit();
4345
});
4446

@@ -52,7 +54,7 @@
5254
intro.setOptions(scope.ngIntroOptions);
5355

5456
if (scope.ngIntroAutorefresh) {
55-
scope.$watch(function(){
57+
refreshWatch = scope.$watch(function(){
5658
intro.refresh();
5759
});
5860
}
@@ -61,15 +63,15 @@
6163
intro.oncomplete(function() {
6264
scope.ngIntroOncomplete.call(this, scope);
6365
$timeout(function() {scope.$digest();});
64-
navigationWatch();
66+
clearWatches();
6567
});
6668
}
6769

6870
if (scope.ngIntroOnexit) {
6971
intro.onexit(function() {
7072
scope.ngIntroOnexit.call(this, scope);
7173
$timeout(function() {scope.$digest();});
72-
navigationWatch();
74+
clearWatches();
7375
});
7476
}
7577

@@ -114,7 +116,7 @@
114116
callback();
115117
};
116118

117-
var autoStartWatch = scope.$watch('ngIntroAutostart', function (){
119+
var autoStartWatch = scope.$watch('ngIntroAutostart', function () {
118120
if(scope.ngIntroAutostart){
119121
$timeout(function() {
120122
scope.ngIntroMethod();
@@ -127,6 +129,15 @@
127129
if (typeof intro !== 'undefined')
128130
intro.exit();
129131
});
132+
133+
var clearWatches = function() {
134+
if(navigationWatch) navigationWatch();
135+
if(refreshWatch) refreshWatch();
136+
};
137+
138+
scope.$on('$destroy', function() {
139+
clearWatches();
140+
});
130141
}
131142
};
132143
}]);

0 commit comments

Comments
 (0)