Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Unified Diff: third_party/pkg/angular/lib/routing/ng_view.dart

Issue 176943008: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/routing/ng_view.dart
diff --git a/third_party/pkg/angular/lib/routing/ng_view.dart b/third_party/pkg/angular/lib/routing/ng_view.dart
index d62b857e8271c51db55599bcfdddb6d937963347..deb733e57d63e30d9ffa1f8719f8b0ce50c31610 100644
--- a/third_party/pkg/angular/lib/routing/ng_view.dart
+++ b/third_party/pkg/angular/lib/routing/ng_view.dart
@@ -9,33 +9,32 @@ part of angular.routing;
* [NgViewDirective] can work with [NgViewDirective] to define nested views
* for hierarchical routes. For example:
*
- * class MyRouteInitializer implements RouteInitializer {
- * void init(Router router, ViewFactory view) {
- * router.root
- * ..addRoute(
- * name: 'library',
- * path: '/library',
- * enter: view('library.html'),
- * mount: (Route route) => route
- * ..addRoute(
- * name: 'all',
- * path: '/all',
- * enter: view('book_list.html'))
- * ..addRoute(
- * name: 'book',
- * path: '/:bookId',
- * mount: (Route route) => route
- * ..addRoute(
- * name: 'overview',
- * path: '/overview',
- * defaultRoute: true,
- * enter: view('book_overview.html'))
- * ..addRoute(
- * name: 'read',
- * path: '/read',
- * enter: view('book_read.html'))));
- * }
+ * void initRoutes(Router router, ViewFactory view) {
+ * router.root
+ * ..addRoute(
+ * name: 'library',
+ * path: '/library',
+ * enter: view('library.html'),
+ * mount: (Route route) => route
+ * ..addRoute(
+ * name: 'all',
+ * path: '/all',
+ * enter: view('book_list.html'))
+ * ..addRoute(
+ * name: 'book',
+ * path: '/:bookId',
+ * mount: (Route route) => route
+ * ..addRoute(
+ * name: 'overview',
+ * path: '/overview',
+ * defaultRoute: true,
+ * enter: view('book_overview.html'))
+ * ..addRoute(
+ * name: 'read',
+ * path: '/read',
+ * enter: view('book_read.html'))));
* }
+ * }
*
* index.html:
*
@@ -59,36 +58,35 @@ part of angular.routing;
@NgDirective(
selector: 'ng-view',
publishTypes: const [RouteProvider],
- visibility: NgDirective.CHILDREN_VISIBILITY
-)
+ visibility: NgDirective.CHILDREN_VISIBILITY)
class NgViewDirective implements NgDetachAware, RouteProvider {
final NgRoutingHelper locationService;
final BlockCache blockCache;
- final Scope scope;
final Injector injector;
final Element element;
+ final Scope scope;
RouteHandle _route;
Block _previousBlock;
Scope _previousScope;
Route _viewRoute;
- NgViewDirective(this.element, this.blockCache, this.scope, Injector injector, Router router)
- : injector = injector, locationService = injector.get(NgRoutingHelper) {
+ NgViewDirective(this.element, this.blockCache,
+ Injector injector, Router router,
+ this.scope)
+ : injector = injector,
+ locationService = injector.get(NgRoutingHelper)
+ {
RouteProvider routeProvider = injector.parent.get(NgViewDirective);
- if (routeProvider != null) {
- _route = routeProvider.route.newHandle();
- } else {
- _route = router.root.newHandle();
- }
+ _route = routeProvider != null ?
+ routeProvider.route.newHandle() :
+ router.root.newHandle();
locationService._registerPortal(this);
_maybeReloadViews();
}
void _maybeReloadViews() {
- if (_route.isActive) {
- locationService._reloadViews(startingFrom: _route);
- }
+ if (_route.isActive) locationService._reloadViews(startingFrom: _route);
}
detach() {
@@ -96,7 +94,7 @@ class NgViewDirective implements NgDetachAware, RouteProvider {
locationService._unregisterPortal(this);
}
- _show(String templateUrl, Route route) {
+ _show(String templateUrl, Route route, List<Module> modules) {
assert(route.isActive);
if (_viewRoute != null) return;
@@ -110,23 +108,28 @@ class NgViewDirective implements NgDetachAware, RouteProvider {
_cleanUp();
});
- blockCache.fromUrl(templateUrl).then((blockFactory) {
+ var viewInjector = injector;
+ if (modules != null) {
+ viewInjector = forceNewDirectivesAndFilters(viewInjector, modules);
+ }
+
+ var newDirectives = viewInjector.get(DirectiveMap);
+ blockCache.fromUrl(templateUrl, newDirectives).then((blockFactory) {
_cleanUp();
- _previousScope = scope.$new();
+ _previousScope = scope.createChild(new PrototypeMap(scope.context));
_previousBlock = blockFactory(
- injector.createChild([new Module()..value(Scope, _previousScope)]));
+ viewInjector.createChild(
+ [new Module()..value(Scope, _previousScope)]));
_previousBlock.elements.forEach((elm) => element.append(elm));
});
}
_cleanUp() {
- if (_previousBlock == null) {
- return;
- }
+ if (_previousBlock == null) return;
_previousBlock.remove();
- _previousScope.$destroy();
+ _previousScope.destroy();
_previousBlock = null;
_previousScope = null;

Powered by Google App Engine
This is Rietveld 408576698