From da2240f1fcee8cbd695eb44a63337b09116b8fcb Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Wed, 13 Apr 2016 14:06:34 +0300 Subject: [PATCH 1/3] revert: "fix(ngRoute): allow `ngView` to be included in an asynchronously loaded template" This reverts commit 5e37b2a7fd0b837fdab97bb3525dabefc0ea848a. Eagerly loading `$route`, could break tests, because it might request the root or default route template (something `$httpBackend` would know nothing about). It will be re-applied for `v1.6.x`, with a breaking change notice and possibly a way to disable the feature is tests. Fixes #14337 --- src/ngRoute/route.js | 6 +----- test/ngRoute/directive/ngViewSpec.js | 31 ---------------------------- test/ngRoute/routeSpec.js | 15 -------------- 3 files changed, 1 insertion(+), 51 deletions(-) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index e0a720e39365..f023967a22a8 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -17,11 +17,7 @@ */ /* global -ngRouteModule */ var ngRouteModule = angular.module('ngRoute', ['ng']). - provider('$route', $RouteProvider). - // Ensure `$route` will be instantiated in time to capture the initial - // `$locationChangeSuccess` event. This is necessary in case `ngView` is - // included in an asynchronously loaded template. - run(['$route', angular.noop]), + provider('$route', $RouteProvider), $routeMinErr = angular.$$minErr('ngRoute'); /** diff --git a/test/ngRoute/directive/ngViewSpec.js b/test/ngRoute/directive/ngViewSpec.js index c7e9652a13f7..daab5f26c987 100644 --- a/test/ngRoute/directive/ngViewSpec.js +++ b/test/ngRoute/directive/ngViewSpec.js @@ -1027,34 +1027,3 @@ describe('ngView animations', function() { )); }); }); - -describe('ngView in async template', function() { - beforeEach(module('ngRoute')); - beforeEach(module(function($compileProvider, $provide, $routeProvider) { - $compileProvider.directive('asyncView', function() { - return {templateUrl: 'async-view.html'}; - }); - - $provide.decorator('$templateRequest', function($timeout) { - return function() { - return $timeout(angular.identity, 500, false, ''); - }; - }); - - $routeProvider.when('/', {template: 'Hello, world !'}); - })); - - - it('should work correctly upon initial page load', - // Injecting `$location` here is necessary, so that it gets instantiated early - inject(function($compile, $location, $rootScope, $timeout) { - var elem = $compile('')($rootScope); - $rootScope.$digest(); - $timeout.flush(500); - - expect(elem.text()).toBe('Hello, world !'); - - dealoc(elem); - }) - ); -}); diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index dc247a4788ea..b6527438af28 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -23,21 +23,6 @@ describe('$route', function() { dealoc(element); }); - it('should be loaded upon initial load (even if `ngView` is loaded async)', function() { - module(function($routeProvider) { - $routeProvider.when('/', {template: 'Hello, world !'}); - }); - - inject(function($location, $rootScope) { - $location.path('/'); - $rootScope.$digest(); - }); - - inject(function($route) { - expect($route.current).toBeDefined(); - }); - }); - it('should allow cancellation via $locationChangeStart via $routeChangeStart', function() { module(function($routeProvider) { $routeProvider.when('/Edit', { From 8f3ef60aa561229cd6d739fb77499eb9c9999379 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Wed, 13 Apr 2016 14:29:24 +0300 Subject: [PATCH 2/3] docs(ngView): add known issue about asynchronously loaded `ngView` --- src/ngRoute/directive/ngView.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ngRoute/directive/ngView.js b/src/ngRoute/directive/ngView.js index cdd1a30e9e0b..90aae309e781 100644 --- a/src/ngRoute/directive/ngView.js +++ b/src/ngRoute/directive/ngView.js @@ -26,6 +26,12 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory); * * The enter and leave animation occur concurrently. * + * @knownIssue If `ngView` is contained in an asynchronously loaded templated (i.e. not directly + * inside your main HTML file, then you need to make sure that `$route` is instantiated + * in time to capture the initial `$locationChangeStart` event and load the appropriate + * view. One way to ensure `$route` will be instantiated in time, it to have it as a + * dependency in a `.run` block: `myModule.run(['$route', function() {}]);` + * * @scope * @priority 400 * @param {string=} onload Expression to evaluate whenever the view updates. From fa274820baed9ed32acd27fca868be735a7d0933 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Wed, 13 Apr 2016 15:03:44 +0300 Subject: [PATCH 3/3] fixup1 --- src/ngRoute/directive/ngView.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ngRoute/directive/ngView.js b/src/ngRoute/directive/ngView.js index 90aae309e781..30c3397d5160 100644 --- a/src/ngRoute/directive/ngView.js +++ b/src/ngRoute/directive/ngView.js @@ -26,11 +26,12 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory); * * The enter and leave animation occur concurrently. * - * @knownIssue If `ngView` is contained in an asynchronously loaded templated (i.e. not directly - * inside your main HTML file, then you need to make sure that `$route` is instantiated - * in time to capture the initial `$locationChangeStart` event and load the appropriate - * view. One way to ensure `$route` will be instantiated in time, it to have it as a - * dependency in a `.run` block: `myModule.run(['$route', function() {}]);` + * @knownIssue If `ngView` is contained in an asynchronously loaded template (e.g. in another + * directive's templateUrl or in a template loaded using `ngInclude`), then you need to + * make sure that `$route` is instantiated in time to capture the initial + * `$locationChangeStart` event and load the appropriate view. One way to achieve this + * is to have it as a dependency in a `.run` block: + * `myModule.run(['$route', function() {}]);` * * @scope * @priority 400