app/assets/javascripts/angular/angular-route.js in angular-rails-engine-1.2.0.2 vs app/assets/javascripts/angular/angular-route.js in angular-rails-engine-1.2.3.0

- old
+ new

@@ -1,8 +1,8 @@ /** - * @license AngularJS v1.2.0 - * (c) 2010-2012 Google, Inc. http://angularjs.org + * @license AngularJS v1.2.3 + * (c) 2010-2014 Google, Inc. http://angularjs.org * License: MIT */ (function(window, angular, undefined) {'use strict'; /** @@ -12,10 +12,13 @@ * * # ngRoute * * The `ngRoute` module provides routing and deeplinking services and directives for angular apps. * + * ## Example + * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`. + * * {@installModule route} * * <div doc-module-components="ngRoute"></div> */ /* global -ngRouteModule */ @@ -27,12 +30,16 @@ * @name ngRoute.$routeProvider * @function * * @description * - * Used for configuring routes. See {@link ngRoute.$route $route} for an example. + * Used for configuring routes. + * + * ## Example + * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`. * + * ## Dependencies * Requires the {@link ngRoute `ngRoute`} module to be installed. */ function $RouteProvider(){ function inherit(parent, extra) { return angular.extend(new (angular.extend(function() {}, {prototype:parent}))(), extra); @@ -807,12 +814,11 @@ return { restrict: 'ECA', terminal: true, priority: 400, transclude: 'element', - compile: function(element, attr, linker) { - return function(scope, $element, attr) { + link: function(scope, $element, attr, ctrl, $transclude) { var currentScope, currentElement, autoScrollExp = attr.autoscroll, onloadExp = attr.onload || ''; @@ -834,45 +840,50 @@ var locals = $route.current && $route.current.locals, template = locals && locals.$template; if (template) { var newScope = scope.$new(); - linker(newScope, function(clone) { - clone.html(template); - $animate.enter(clone, null, currentElement || $element, function onNgViewEnter () { - if (angular.isDefined(autoScrollExp) - && (!autoScrollExp || scope.$eval(autoScrollExp))) { - $anchorScroll(); - } - }); - cleanupLastView(); + // Note: This will also link all children of ng-view that were contained in the original + // html. If that content contains controllers, ... they could pollute/change the scope. + // However, using ng-view on an element with additional content does not make sense... + // Note: We can't remove them in the cloneAttchFn of $transclude as that + // function is called before linking the content, which would apply child + // directives to non existing elements. + var clone = $transclude(newScope, angular.noop); + clone.html(template); + $animate.enter(clone, null, currentElement || $element, function onNgViewEnter () { + if (angular.isDefined(autoScrollExp) + && (!autoScrollExp || scope.$eval(autoScrollExp))) { + $anchorScroll(); + } + }); - var link = $compile(clone.contents()), - current = $route.current; + cleanupLastView(); - currentScope = current.scope = newScope; - currentElement = clone; + var link = $compile(clone.contents()), + current = $route.current; - if (current.controller) { - locals.$scope = currentScope; - var controller = $controller(current.controller, locals); - if (current.controllerAs) { - currentScope[current.controllerAs] = controller; - } - clone.data('$ngControllerController', controller); - clone.children().data('$ngControllerController', controller); + currentScope = current.scope = newScope; + currentElement = clone; + + if (current.controller) { + locals.$scope = currentScope; + var controller = $controller(current.controller, locals); + if (current.controllerAs) { + currentScope[current.controllerAs] = controller; } + clone.data('$ngControllerController', controller); + clone.children().data('$ngControllerController', controller); + } - link(currentScope); - currentScope.$emit('$viewContentLoaded'); - currentScope.$eval(onloadExp); - }); + link(currentScope); + currentScope.$emit('$viewContentLoaded'); + currentScope.$eval(onloadExp); } else { cleanupLastView(); } } - }; } }; }