diff --git a/lib/mock/test_bed.dart b/lib/mock/test_bed.dart index e81f4d04e..32f44317d 100644 --- a/lib/mock/test_bed.dart +++ b/lib/mock/test_bed.dart @@ -8,7 +8,7 @@ part of angular.mock; */ class TestBed { final Injector injector; - final Scope rootScope; + final RootScope rootScope; final Compiler compiler; final Parser _parser; final Expando expando; diff --git a/lib/routing/ng_view.dart b/lib/routing/ng_view.dart index 222daf246..ab2da5de5 100644 --- a/lib/routing/ng_view.dart +++ b/lib/routing/ng_view.dart @@ -54,7 +54,7 @@ part of angular.routing; @Decorator( selector: 'ng-view', module: NgView.module, - visibility: Directive.CHILDREN_VISIBILITY) + children: Directive.TRANSCLUDE_CHILDREN) class NgView implements DetachAware, RouteProvider { static final Module _module = new Module() ..bind(RouteProvider, toFactory: (i) => i.get(NgView)); @@ -63,17 +63,16 @@ class NgView implements DetachAware, RouteProvider { final NgRoutingHelper locationService; final ViewCache viewCache; final Injector injector; - final Element element; final Scope scope; + final ViewPort _viewPort; + RouteHandle _route; View _view; Scope _scope; Route _viewRoute; - NgView(this.element, this.viewCache, - Injector injector, Router router, - this.scope) + NgView(this.viewCache, Injector injector, Router router, this.scope, this._viewPort) : injector = injector, locationService = injector.get(NgRoutingHelper) { @@ -119,24 +118,31 @@ class NgView implements DetachAware, RouteProvider { viewFuture.then((viewFactory) { _cleanUp(); _scope = scope.createChild(new PrototypeMap(scope.context)); - _view = viewFactory( - viewInjector.createChild([new Module()..bind(Scope, toValue: _scope)])); - _view.nodes.forEach((elm) => element.append(elm)); + _view = viewFactory(viewInjector.createChild([new Module()..bind(Scope, toValue: _scope)])); + _scope.rootScope.domWrite(() { + _viewPort.insert(_view); + }); }); } _cleanUp() { if (_view == null) return; - _view.nodes.forEach((node) => node.remove()); - _scope.destroy(); + var view = _view; + var childScope = _scope; + _scope.rootScope.domWrite(() { + _viewPort.remove(view); + childScope.destroy(); + }); _view = null; _scope = null; } Route get route => _viewRoute; + String get routeName => _viewRoute.name; + Map get parameters { var res = {}; var p = _viewRoute; diff --git a/test/routing/ng_view_spec.dart b/test/routing/ng_view_spec.dart index e165aea33..63cdda390 100644 --- a/test/routing/ng_view_spec.dart +++ b/test/routing/ng_view_spec.dart @@ -28,27 +28,30 @@ main() { it('should switch template', async(() { - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('Foo'); router.route('/bar'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('Bar'); router.route('/foo'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('Foo'); })); it('should expose NgView as RouteProvider', async(() { - _.compile(''); + _.compile('
'); router.route('/foo'); microLeap(); - _.rootScope.apply(); + _.rootScope.flush(); expect(_.rootScope.context['p'].injector.get(RouteProvider) is NgView).toBeTruthy(); })); @@ -56,29 +59,31 @@ main() { it('should switch template when route is already active', async(() { // Force the routing system to initialize. - _.compile(''); + _.compile('
'); router.route('/foo'); microLeap(); - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); - _.rootScope.apply(); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('Foo'); })); it('should clear template when route is deactivated', async(() { - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('Foo'); router.route('/baz'); // route without a template microLeap(); + _.rootScope.flush(); expect(root.text).toEqual(''); })); @@ -111,25 +116,29 @@ main() { }); it('should switch nested templates', async(() { - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/library/all'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('LibraryBooks'); router.route('/library/1234'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('LibraryBook 1234'); // nothing should change here router.route('/library/1234/overview'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('LibraryBook 1234'); // nothing should change here router.route('/library/1234/read'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('LibraryRead Book 1234'); })); }); @@ -157,11 +166,12 @@ main() { }); it('should switch inline templates', async(() { - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('Hello'); })); }); diff --git a/test/routing/routing_spec.dart b/test/routing/routing_spec.dart index bbc63cd31..2e850c0eb 100644 --- a/test/routing/routing_spec.dart +++ b/test/routing/routing_spec.dart @@ -158,11 +158,12 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '

Foo

')); - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); + _.rootScope.flush(); expect(enterCount).toBe(1); expect(root.text).toEqual('Foo'); @@ -231,17 +232,19 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '

Foo

')); - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('Foo'); expect(leaveCount).toBe(0); router.route('/bar'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual(''); expect(leaveCount).toBe(1); @@ -263,11 +266,12 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
Old!
')); - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('New!'); })); @@ -288,11 +292,12 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
Old!
')); - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); + _.rootScope.flush(); expect(root.text).toEqual('New!'); })); @@ -313,7 +318,7 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
{{\'World\' | hello}}
')); - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo'); @@ -339,7 +344,7 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
{{\'World\' | hello}}
')); - Element root = _.compile(''); + Element root = _.compile('
'); expect(root.text).toEqual(''); router.route('/foo');