@@ -6,6 +6,7 @@ import 'dart:html';
66
77import 'package:angular2/angular2.dart' ;
88
9+ import '../../utils/angular/properties/properties.dart' ;
910import '../../utils/disposer/disposer.dart' ;
1011
1112import 'deferred_content_aware.dart' ;
@@ -31,35 +32,51 @@ class DeferredContentDirective implements OnDestroy {
3132 EmbeddedViewRef _viewRef;
3233 TemplateRef _template;
3334
35+ /// Create a placeholder element to maintain content size when hidden.
36+ ///
37+ /// Used like *deferredContent="true".
38+ bool _preserveDimensions = false ;
39+ @Input ('deferredContent' )
40+ set preserveDimensions (value) {
41+ // If it's just *deferredContent, default to false.
42+ _preserveDimensions = getBool (value ?? false );
43+ }
44+
3445 // Keep around the current state.
3546 bool _visible = false ;
3647
3748 void _setVisible (bool value) {
3849 if (value == _visible) return ;
3950 if (value) {
40- // Remove the placeholder and add the deferred content.
41- _placeholder.remove ();
51+ if (_preserveDimensions) {
52+ // Remove the placeholder and add the deferred content.
53+ _placeholder.remove ();
54+ }
4255 _viewRef = _viewContainer.createEmbeddedView (_template);
4356 } else {
44- // Save the dimensions of the deferred content.
45- var rootNodes = _viewRef? .rootNodes ?? [];
46- var content = rootNodes.length > 0 ? rootNodes.first : null ;
47- if (content is HtmlElement ) {
48- // This isn't in DomService.schedule{Read,Write} because
49- // it needs to work with components that aren't scheduled.
50- var dimensions = content.getBoundingClientRect ();
51- _placeholder.style
52- ..width = '${dimensions .width }px'
53- ..height = '${dimensions .height }px' ;
57+ if (_preserveDimensions) {
58+ // Save the dimensions of the deferred content.
59+ var rootNodes = _viewRef? .rootNodes ?? [];
60+ var content = rootNodes.length > 0 ? rootNodes.first : null ;
61+ if (content is HtmlElement ) {
62+ // This isn't in DomService.schedule{Read,Write} because
63+ // it needs to work with components that aren't scheduled.
64+ var dimensions = content.getBoundingClientRect ();
65+ _placeholder.style
66+ ..width = '${dimensions .width }px'
67+ ..height = '${dimensions .height }px' ;
68+ }
5469 }
5570
5671 // Remove the deferred content.
5772 _viewContainer.clear ();
5873
59- // Add the placeholder so the parent's size doesn't change.
60- var container = _viewContainer.element? .nativeElement;
61- if (container != null ) {
62- container.parentNode.insertBefore (_placeholder, container);
74+ if (_preserveDimensions) {
75+ // Add the placeholder so the parent's size doesn't change.
76+ var container = _viewContainer.element? .nativeElement;
77+ if (container != null ) {
78+ container.parentNode.insertBefore (_placeholder, container);
79+ }
6380 }
6481 }
6582 _visible = value;
0 commit comments