|
34 | 34 | link: function(scope, element, attrs) { |
35 | 35 |
|
36 | 36 | var intro; |
| 37 | + var refreshWatch; |
| 38 | + var navigationWatch; |
37 | 39 |
|
38 | 40 | scope.ngIntroMethod = function(step) { |
39 | 41 |
|
40 | 42 |
|
41 | | - var navigationWatch = scope.$on('$locationChangeStart', function(){ |
| 43 | + navigationWatch = scope.$on('$locationChangeStart', function(){ |
42 | 44 | intro.exit(); |
43 | 45 | }); |
44 | 46 |
|
|
52 | 54 | intro.setOptions(scope.ngIntroOptions); |
53 | 55 |
|
54 | 56 | if (scope.ngIntroAutorefresh) { |
55 | | - scope.$watch(function(){ |
| 57 | + refreshWatch = scope.$watch(function(){ |
56 | 58 | intro.refresh(); |
57 | 59 | }); |
58 | 60 | } |
|
61 | 63 | intro.oncomplete(function() { |
62 | 64 | scope.ngIntroOncomplete.call(this, scope); |
63 | 65 | $timeout(function() {scope.$digest();}); |
64 | | - navigationWatch(); |
| 66 | + clearWatches(); |
65 | 67 | }); |
66 | 68 | } |
67 | 69 |
|
68 | 70 | if (scope.ngIntroOnexit) { |
69 | 71 | intro.onexit(function() { |
70 | 72 | scope.ngIntroOnexit.call(this, scope); |
71 | 73 | $timeout(function() {scope.$digest();}); |
72 | | - navigationWatch(); |
| 74 | + clearWatches(); |
73 | 75 | }); |
74 | 76 | } |
75 | 77 |
|
|
114 | 116 | callback(); |
115 | 117 | }; |
116 | 118 |
|
117 | | - var autoStartWatch = scope.$watch('ngIntroAutostart', function (){ |
| 119 | + var autoStartWatch = scope.$watch('ngIntroAutostart', function () { |
118 | 120 | if(scope.ngIntroAutostart){ |
119 | 121 | $timeout(function() { |
120 | 122 | scope.ngIntroMethod(); |
|
127 | 129 | if (typeof intro !== 'undefined') |
128 | 130 | intro.exit(); |
129 | 131 | }); |
| 132 | + |
| 133 | + var clearWatches = function() { |
| 134 | + if(navigationWatch) navigationWatch(); |
| 135 | + if(refreshWatch) refreshWatch(); |
| 136 | + }; |
| 137 | + |
| 138 | + scope.$on('$destroy', function() { |
| 139 | + clearWatches(); |
| 140 | + }); |
130 | 141 | } |
131 | 142 | }; |
132 | 143 | }]); |
|
0 commit comments