Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

revert: "fix(ngRoute): allow ngView to be included in an asynchronously loaded template" #14424

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ngRoute/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
*
* The enter and leave animation occur concurrently.
*
* @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
* @param {string=} onload Expression to evaluate whenever the view updates.
Expand Down
6 changes: 1 addition & 5 deletions src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/**
Expand Down
31 changes: 0 additions & 31 deletions test/ngRoute/directive/ngViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<ng-view></ng-view>');
};
});

$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('<async-view></async-view>')($rootScope);
$rootScope.$digest();
$timeout.flush(500);

expect(elem.text()).toBe('Hello, world !');

dealoc(elem);
})
);
});
15 changes: 0 additions & 15 deletions test/ngRoute/routeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down