From 9486590e1be7282bb0e87586a35ca0bee6c64ee0 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Sun, 19 Feb 2012 12:31:11 -0800 Subject: refactor(ng:view) Make $route scope agnostic, add $contentLoaded event Problems: - controller was instantiated immediately on $afterRouteChange (even if no content), that's different compare to ng:controller, which instantiates controllers after compiling - route listened on current scope ($afterRouteChange), so if you were listening on $rootScope ($afterRouteChange), you get called first and current.scope === undefined, which is flaky - route handles scope destroying, but scope is created by ng:view - route fires after/before route change even if there is no route (when no otherwise specified) Solution: - route has no idea about scope, whole scope business moved to ng:view (creating/destroying) - scope is created (and controller instantiated) AFTER compiling the content - that means on $afterRouteChange - there is no scope yet (current.scope === undefined) - added $contentLoaded event fired by ng:view, after linking the content --- src/service/route.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/service') diff --git a/src/service/route.js b/src/service/route.js index b7f8bd02..8d8086af 100644 --- a/src/service/route.js +++ b/src/service/route.js @@ -237,22 +237,16 @@ function $RouteProvider(){ function updateRoute() { var next = parseRoute(), - last = $route.current, - Controller; + last = $route.current; if (next && last && next.$route === last.$route && equals(next.pathParams, last.pathParams) && !next.reloadOnSearch && !forceReload) { - next.scope = last.scope; - $route.current = next; - copy(next.params, $routeParams); - last.scope && last.scope.$emit('$routeUpdate'); - } else { + last.params = next.params; + copy(last.params, $routeParams); + $rootScope.$broadcast('$routeUpdate', last); + } else if (next || last) { forceReload = false; $rootScope.$broadcast('$beforeRouteChange', next, last); - if (last && last.scope) { - last.scope.$destroy(); - last.scope = null; - } $route.current = next; if (next) { if (next.redirectTo) { @@ -308,7 +302,5 @@ function $RouteProvider(){ }); return result.join(''); } - - }]; } -- cgit v1.2.3