|
26 | 26 | * functionality, call `$uiViewScrollProvider.useAnchorScroll()`.*
|
27 | 27 | *
|
28 | 28 | * @param {string=} onload Expression to evaluate whenever the view updates.
|
29 |
| - * |
| 29 | + * |
30 | 30 | * @example
|
31 |
| - * A view can be unnamed or named. |
| 31 | + * A view can be unnamed or named. |
32 | 32 | * <pre>
|
33 | 33 | * <!-- Unnamed -->
|
34 |
| - * <div ui-view></div> |
35 |
| - * |
| 34 | + * <div ui-view></div> |
| 35 | + * |
36 | 36 | * <!-- Named -->
|
37 | 37 | * <div ui-view="viewName"></div>
|
38 | 38 | * </pre>
|
39 | 39 | *
|
40 |
| - * You can only have one unnamed view within any template (or root html). If you are only using a |
| 40 | + * You can only have one unnamed view within any template (or root html). If you are only using a |
41 | 41 | * single view and it is unnamed then you can populate it like so:
|
42 | 42 | * <pre>
|
43 |
| - * <div ui-view></div> |
| 43 | + * <div ui-view></div> |
44 | 44 | * $stateProvider.state("home", {
|
45 | 45 | * template: "<h1>HELLO!</h1>"
|
46 | 46 | * })
|
47 | 47 | * </pre>
|
48 |
| - * |
| 48 | + * |
49 | 49 | * The above is a convenient shortcut equivalent to specifying your view explicitly with the {@link ui.router.state.$stateProvider#views `views`}
|
50 | 50 | * config property, by name, in this case an empty name:
|
51 | 51 | * <pre>
|
|
54 | 54 | * "": {
|
55 | 55 | * template: "<h1>HELLO!</h1>"
|
56 | 56 | * }
|
57 |
| - * } |
| 57 | + * } |
58 | 58 | * })
|
59 | 59 | * </pre>
|
60 |
| - * |
61 |
| - * But typically you'll only use the views property if you name your view or have more than one view |
62 |
| - * in the same template. There's not really a compelling reason to name a view if its the only one, |
| 60 | + * |
| 61 | + * But typically you'll only use the views property if you name your view or have more than one view |
| 62 | + * in the same template. There's not really a compelling reason to name a view if its the only one, |
63 | 63 | * but you could if you wanted, like so:
|
64 | 64 | * <pre>
|
65 | 65 | * <div ui-view="main"></div>
|
66 |
| - * </pre> |
| 66 | + * </pre> |
67 | 67 | * <pre>
|
68 | 68 | * $stateProvider.state("home", {
|
69 | 69 | * views: {
|
70 | 70 | * "main": {
|
71 | 71 | * template: "<h1>HELLO!</h1>"
|
72 | 72 | * }
|
73 |
| - * } |
| 73 | + * } |
74 | 74 | * })
|
75 | 75 | * </pre>
|
76 |
| - * |
| 76 | + * |
77 | 77 | * Really though, you'll use views to set up multiple views:
|
78 | 78 | * <pre>
|
79 | 79 | * <div ui-view></div>
|
80 |
| - * <div ui-view="chart"></div> |
81 |
| - * <div ui-view="data"></div> |
| 80 | + * <div ui-view="chart"></div> |
| 81 | + * <div ui-view="data"></div> |
82 | 82 | * </pre>
|
83 |
| - * |
| 83 | + * |
84 | 84 | * <pre>
|
85 | 85 | * $stateProvider.state("home", {
|
86 | 86 | * views: {
|
|
93 | 93 | * "data": {
|
94 | 94 | * template: "<data_thing/>"
|
95 | 95 | * }
|
96 |
| - * } |
| 96 | + * } |
97 | 97 | * })
|
98 | 98 | * </pre>
|
99 | 99 | *
|
@@ -190,32 +190,45 @@ function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate)
|
190 | 190 | updateView(true);
|
191 | 191 |
|
192 | 192 | function cleanupLastView() {
|
193 |
| - if (previousEl) { |
194 |
| - previousEl.remove(); |
195 |
| - previousEl = null; |
| 193 | + var _previousEl = previousEl; |
| 194 | + var _currentScope = currentScope; |
| 195 | + |
| 196 | + if (_currentScope) { |
| 197 | + _currentScope._willBeDestroyed = true; |
196 | 198 | }
|
197 | 199 |
|
198 |
| - if (currentScope) { |
199 |
| - currentScope.$destroy(); |
200 |
| - currentScope = null; |
| 200 | + function cleanOld() { |
| 201 | + if (_previousEl) { |
| 202 | + _previousEl.remove(); |
| 203 | + } |
| 204 | + |
| 205 | + if (_currentScope) { |
| 206 | + _currentScope.$destroy(); |
| 207 | + } |
201 | 208 | }
|
202 | 209 |
|
203 | 210 | if (currentEl) {
|
204 | 211 | renderer.leave(currentEl, function() {
|
| 212 | + cleanOld(); |
205 | 213 | previousEl = null;
|
206 | 214 | });
|
207 | 215 |
|
208 | 216 | previousEl = currentEl;
|
209 |
| - currentEl = null; |
| 217 | + } else { |
| 218 | + cleanOld(); |
| 219 | + previousEl = null; |
210 | 220 | }
|
| 221 | + |
| 222 | + currentEl = null; |
| 223 | + currentScope = null; |
211 | 224 | }
|
212 | 225 |
|
213 | 226 | function updateView(firstTime) {
|
214 | 227 | var newScope,
|
215 | 228 | name = getUiViewName(scope, attrs, $element, $interpolate),
|
216 | 229 | previousLocals = name && $state.$current && $state.$current.locals[name];
|
217 | 230 |
|
218 |
| - if (!firstTime && previousLocals === latestLocals) return; // nothing to do |
| 231 | + if (!firstTime && previousLocals === latestLocals || scope._willBeDestroyed) return; // nothing to do |
219 | 232 | newScope = scope.$new();
|
220 | 233 | latestLocals = $state.$current.locals[name];
|
221 | 234 |
|
|
0 commit comments