@@ -58,22 +58,22 @@ part of angular.routing;
58
58
@NgDirective (
59
59
selector: 'ng-view' ,
60
60
publishTypes: const [RouteProvider ],
61
+ children: NgAnnotation .TRANSCLUDE_CHILDREN ,
61
62
visibility: NgDirective .CHILDREN_VISIBILITY )
62
63
class NgViewDirective implements NgDetachAware , RouteProvider {
63
64
final NgRoutingHelper locationService;
64
65
final ViewCache viewCache;
65
66
final Injector injector;
66
- final Element element;
67
67
final Scope scope;
68
68
RouteHandle _route;
69
+ final ViewPort _viewPort;
69
70
70
71
View _view;
71
- Scope _scope ;
72
+ Scope _childScope ;
72
73
Route _viewRoute;
73
74
74
- NgViewDirective (this .element, this .viewCache,
75
- Injector injector, Router router,
76
- this .scope)
75
+ NgViewDirective (this .viewCache, Injector injector,
76
+ Router router, this .scope, this ._viewPort)
77
77
: injector = injector,
78
78
locationService = injector.get (NgRoutingHelper )
79
79
{
@@ -114,29 +114,33 @@ class NgViewDirective implements NgDetachAware, RouteProvider {
114
114
}
115
115
116
116
var newDirectives = viewInjector.get (DirectiveMap );
117
+
117
118
viewCache.fromUrl (templateUrl, newDirectives).then ((viewFactory) {
118
119
_cleanUp ();
119
- _scope = scope.createChild (new PrototypeMap (scope.context));
120
- _view = viewFactory (
121
- viewInjector. createChild (
122
- [ new Module ().. value ( Scope , _scope)]));
123
-
124
- _view.nodes. forEach ((elm) => element. append (elm) );
120
+ _childScope = scope.createChild (new PrototypeMap (scope.context));
121
+ var view = _view = viewFactory (viewInjector. createChild (
122
+ [ new Module ().. value ( Scope , _childScope)]));
123
+ _childScope.rootScope. domWrite (() {
124
+ _viewPort. insert (view);
125
+ } );
125
126
});
126
127
}
127
128
128
129
_cleanUp () {
129
130
if (_view == null ) return ;
130
131
131
- _view.nodes.forEach ((node) => node.remove ());
132
- _scope.destroy ();
133
-
132
+ var view = _view;
133
+ _childScope.rootScope.domWrite (() {
134
+ _viewPort.remove (view);
135
+ });
136
+ _childScope.destroy ();
134
137
_view = null ;
135
- _scope = null ;
138
+ _childScope = null ;
136
139
}
137
140
138
141
Route get route => _viewRoute;
139
142
String get routeName => _viewRoute.name;
143
+
140
144
Map <String , String > get parameters {
141
145
var res = < String , String > {};
142
146
var p = _viewRoute;
0 commit comments