mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
feat($route): rename template -> tempalteUrl and add support for inline templates
BREAKING CHANGE: template in $route definition is now templateUrl To migrate just rename `template` to `templateUrl`.
This commit is contained in:
parent
7c24282188
commit
0a6e464a93
7 changed files with 113 additions and 86 deletions
|
|
@ -35,8 +35,8 @@ In this example we have a simple app which consist of two screens:
|
|||
angular.module('deepLinking', ['ngSanitize'])
|
||||
.config(function($routeProvider) {
|
||||
$routeProvider.
|
||||
when("/welcome", {template:'welcome.html', controller:WelcomeCntl}).
|
||||
when("/settings", {template:'settings.html', controller:SettingsCntl});
|
||||
when("/welcome", {templateUrl:'welcome.html', controller:WelcomeCntl}).
|
||||
when("/settings", {templateUrl:'settings.html', controller:SettingsCntl});
|
||||
});
|
||||
|
||||
AppCntl.$inject = ['$scope', '$route']
|
||||
|
|
|
|||
|
|
@ -72,8 +72,8 @@ __`app/js/app.js`:__
|
|||
angular.module('phonecat', []).
|
||||
config(['$routeProvider', function($routeProvider) {
|
||||
$routeProvider.
|
||||
when('/phones', {template: 'partials/phone-list.html', controller: PhoneListCtrl}).
|
||||
when('/phones/:phoneId', {template: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
|
||||
when('/phones', {templateUrl: 'partials/phone-list.html', controller: PhoneListCtrl}).
|
||||
when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
|
||||
otherwise({redirectTo: '/phones'});
|
||||
}]);
|
||||
</pre>
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
<script>
|
||||
setupModuleLoader(window);
|
||||
angular.module('example', [], function($routeProvider) {
|
||||
$routeProvider.when('/view1', {controller: MyCtrl, template: 'view1.html'});
|
||||
$routeProvider.when('/view2', {controller: MyCtrl, template: 'view2.html'});
|
||||
$routeProvider.when('/view1', {controller: MyCtrl, templateUrl: 'view1.html'});
|
||||
$routeProvider.when('/view2', {controller: MyCtrl, templateUrl: 'view2.html'});
|
||||
|
||||
function MyCtrl($location, $scope) {
|
||||
$scope.url = function() {
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@
|
|||
<file name="script.js">
|
||||
angular.module('ngView', [], function($routeProvider, $locationProvider) {
|
||||
$routeProvider.when('/Book/:bookId', {
|
||||
template: 'book.html',
|
||||
templateUrl: 'book.html',
|
||||
controller: BookCntl
|
||||
});
|
||||
$routeProvider.when('/Book/:bookId/ch/:chapterId', {
|
||||
template: 'chapter.html',
|
||||
templateUrl: 'chapter.html',
|
||||
controller: ChapterCntl
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -29,9 +29,12 @@ function $RouteProvider(){
|
|||
*
|
||||
* - `controller` – `{function()=}` – Controller fn that should be associated with newly
|
||||
* created scope.
|
||||
* - `template` – `{string=}` – path to an html template that should be used by
|
||||
* - `template` – `{string=}` – html template as a string that should be used by
|
||||
* {@link angular.module.ng.$compileProvider.directive.ngView ngView} or
|
||||
* {@link angular.module.ng.$compileProvider.directive.ngInclude ngInclude} directives.
|
||||
* this property takes precedence over `templateUrl`.
|
||||
* - `templateUrl` – `{string=}` – path to an html template that should be used by
|
||||
* {@link angular.module.ng.$compileProvider.directive.ngView ngView}.
|
||||
* - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
|
||||
* be injected into the controller. If any of these dependencies are promises, they will be
|
||||
* resolved and converted to a value before the controller is instantiated and the
|
||||
|
|
@ -49,7 +52,7 @@ function $RouteProvider(){
|
|||
* If `redirectTo` is a function, it will be called with the following parameters:
|
||||
*
|
||||
* - `{Object.<string>}` - route parameters extracted from the current
|
||||
* `$location.path()` by applying the current route template.
|
||||
* `$location.path()` by applying the current route templateUrl.
|
||||
* - `{string}` - current `$location.path()`
|
||||
* - `{Object}` - current `$location.search()`
|
||||
*
|
||||
|
|
@ -152,7 +155,7 @@ function $RouteProvider(){
|
|||
<hr />
|
||||
|
||||
<pre>$location.path() = {{$location.path()}}</pre>
|
||||
<pre>$route.current.template = {{$route.current.template}}</pre>
|
||||
<pre>$route.current.templateUrl = {{$route.current.templateUrl}}</pre>
|
||||
<pre>$route.current.params = {{$route.current.params}}</pre>
|
||||
<pre>$route.current.scope.name = {{$route.current.scope.name}}</pre>
|
||||
<pre>$routeParams = {{$routeParams}}</pre>
|
||||
|
|
@ -173,7 +176,7 @@ function $RouteProvider(){
|
|||
<file name="script.js">
|
||||
angular.module('ngView', [], function($routeProvider, $locationProvider) {
|
||||
$routeProvider.when('/Book/:bookId', {
|
||||
template: 'book.html',
|
||||
templateUrl: 'book.html',
|
||||
controller: BookCntl,
|
||||
resolve: {
|
||||
// I will cause a 1 second delay
|
||||
|
|
@ -185,7 +188,7 @@ function $RouteProvider(){
|
|||
}
|
||||
});
|
||||
$routeProvider.when('/Book/:bookId/ch/:chapterId', {
|
||||
template: 'chapter.html',
|
||||
templateUrl: 'chapter.html',
|
||||
controller: ChapterCntl
|
||||
});
|
||||
|
||||
|
|
@ -365,17 +368,21 @@ function $RouteProvider(){
|
|||
then(function() {
|
||||
if (next) {
|
||||
var keys = [],
|
||||
values = [];
|
||||
values = [],
|
||||
template;
|
||||
|
||||
forEach(next.resolve || {}, function(value, key) {
|
||||
keys.push(key);
|
||||
values.push(isFunction(value) ? $injector.invoke(value) : $injector.get(value));
|
||||
});
|
||||
if (next.template) {
|
||||
if (isDefined(template = next.template)) {
|
||||
} else if (isDefined(template = next.templateUrl)) {
|
||||
template = $http.get(template, {cache: $templateCache}).
|
||||
then(function(response) { return response.data; });
|
||||
}
|
||||
if (isDefined(template)) {
|
||||
keys.push('$template');
|
||||
values.push($http.
|
||||
get(next.template, {cache: $templateCache}).
|
||||
then(function(response) { return response.data; }));
|
||||
values.push(template);
|
||||
}
|
||||
return $q.all(values).then(function(values) {
|
||||
var locals = {};
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ describe('ngView', function() {
|
|||
};
|
||||
});
|
||||
|
||||
$routeProvider.when('/some', {template: '/tpl.html', controller: Ctrl});
|
||||
$routeProvider.when('/some', {templateUrl: '/tpl.html', controller: Ctrl});
|
||||
});
|
||||
|
||||
inject(function($route, $rootScope, $templateCache, $location) {
|
||||
|
|
@ -59,7 +59,7 @@ describe('ngView', function() {
|
|||
|
||||
module(function($controllerProvider, $routeProvider) {
|
||||
$controllerProvider.register('MyCtrl', ['$scope', MyCtrl]);
|
||||
$routeProvider.when('/foo', {controller: 'MyCtrl', template: '/tpl.html'});
|
||||
$routeProvider.when('/foo', {controller: 'MyCtrl', templateUrl: '/tpl.html'});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope, $templateCache) {
|
||||
|
|
@ -75,8 +75,8 @@ describe('ngView', function() {
|
|||
|
||||
it('should load content via xhr when route changes', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'myUrl1'});
|
||||
$routeProvider.when('/bar', {template: 'myUrl2'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'myUrl1'});
|
||||
$routeProvider.when('/bar', {templateUrl: 'myUrl2'});
|
||||
});
|
||||
|
||||
inject(function($rootScope, $compile, $httpBackend, $location, $route) {
|
||||
|
|
@ -97,9 +97,34 @@ describe('ngView', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should use inline content route changes', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: '<div>{{1+3}}</div>'});
|
||||
$routeProvider.when('/bar', {template: 'angular is da best'});
|
||||
$routeProvider.when('/blank', {template: ''});
|
||||
});
|
||||
|
||||
inject(function($rootScope, $compile, $location, $route) {
|
||||
expect(element.text()).toEqual('');
|
||||
|
||||
$location.path('/foo');
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('4');
|
||||
|
||||
$location.path('/bar');
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('angular is da best');
|
||||
|
||||
$location.path('/blank');
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should remove all content when location changes to an unknown route', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'myUrl1'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'myUrl1'});
|
||||
});
|
||||
|
||||
inject(function($rootScope, $compile, $location, $httpBackend, $route) {
|
||||
|
|
@ -118,7 +143,7 @@ describe('ngView', function() {
|
|||
|
||||
it('should chain scopes and propagate evals to the child scope', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'myUrl1'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'myUrl1'});
|
||||
});
|
||||
|
||||
inject(function($rootScope, $compile, $location, $httpBackend, $route) {
|
||||
|
|
@ -140,7 +165,7 @@ describe('ngView', function() {
|
|||
it('should be possible to nest ngView in ngInclude', function() {
|
||||
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'viewPartial.html'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'viewPartial.html'});
|
||||
});
|
||||
|
||||
inject(function($httpBackend, $location, $route, $compile, $rootScope) {
|
||||
|
|
@ -156,7 +181,7 @@ describe('ngView', function() {
|
|||
$httpBackend.flush();
|
||||
|
||||
expect(elm.text()).toEqual('include: view: content');
|
||||
expect($route.current.template).toEqual('viewPartial.html');
|
||||
expect($route.current.templateUrl).toEqual('viewPartial.html');
|
||||
dealoc(elm)
|
||||
});
|
||||
});
|
||||
|
|
@ -170,7 +195,7 @@ describe('ngView', function() {
|
|||
}
|
||||
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {controller: ParentCtrl, template: 'viewPartial.html'});
|
||||
$routeProvider.when('/foo', {controller: ParentCtrl, templateUrl: 'viewPartial.html'});
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -209,8 +234,8 @@ describe('ngView', function() {
|
|||
// this is a test for a bad race condition that affected feedback
|
||||
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'myUrl1'});
|
||||
$routeProvider.when('/bar', {template: 'myUrl2'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'myUrl1'});
|
||||
$routeProvider.when('/bar', {templateUrl: 'myUrl2'});
|
||||
});
|
||||
|
||||
inject(function($route, $rootScope, $location, $httpBackend) {
|
||||
|
|
@ -231,7 +256,7 @@ describe('ngView', function() {
|
|||
|
||||
it('should be async even if served from cache', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {controller: noop, template: 'myUrl1'});
|
||||
$routeProvider.when('/foo', {controller: noop, templateUrl: 'myUrl1'});
|
||||
});
|
||||
|
||||
inject(function($route, $rootScope, $location, $templateCache) {
|
||||
|
|
@ -262,7 +287,7 @@ describe('ngView', function() {
|
|||
};
|
||||
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'tpl.html', controller: Ctrl});
|
||||
$routeProvider.when('/foo', {templateUrl: 'tpl.html', controller: Ctrl});
|
||||
});
|
||||
|
||||
inject(function($templateCache, $rootScope, $location) {
|
||||
|
|
@ -282,7 +307,7 @@ describe('ngView', function() {
|
|||
|
||||
it('should destroy previous scope', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'tpl.html'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'tpl.html'});
|
||||
});
|
||||
|
||||
inject(function($templateCache, $rootScope, $location) {
|
||||
|
|
@ -319,8 +344,8 @@ describe('ngView', function() {
|
|||
};
|
||||
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/one', {template: 'one.html', controller: createCtrl('ctrl1')});
|
||||
$routeProvider.when('/two', {template: 'two.html', controller: createCtrl('ctrl2')});
|
||||
$routeProvider.when('/one', {templateUrl: 'one.html', controller: createCtrl('ctrl1')});
|
||||
$routeProvider.when('/two', {templateUrl: 'two.html', controller: createCtrl('ctrl2')});
|
||||
});
|
||||
|
||||
inject(function($httpBackend, $rootScope, $location) {
|
||||
|
|
@ -368,9 +393,9 @@ describe('ngView', function() {
|
|||
}
|
||||
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/bar', {template: 'tpl.html', controller: createController('bar')});
|
||||
$routeProvider.when('/bar', {templateUrl: 'tpl.html', controller: createController('bar')});
|
||||
$routeProvider.when('/foo', {
|
||||
template: 'tpl.html', controller: createController('foo'), reloadOnSearch: false});
|
||||
templateUrl: 'tpl.html', controller: createController('foo'), reloadOnSearch: false});
|
||||
});
|
||||
|
||||
inject(function($templateCache, $location, $rootScope) {
|
||||
|
|
@ -393,7 +418,7 @@ describe('ngView', function() {
|
|||
|
||||
it('should evaluate onload expression after linking the content', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'tpl.html'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'tpl.html'});
|
||||
});
|
||||
|
||||
inject(function($templateCache, $location, $rootScope) {
|
||||
|
|
@ -414,7 +439,7 @@ describe('ngView', function() {
|
|||
}
|
||||
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'tpl.html', controller: MyCtrl});
|
||||
$routeProvider.when('/foo', {templateUrl: 'tpl.html', controller: MyCtrl});
|
||||
});
|
||||
|
||||
inject(function($templateCache, $location, $rootScope, $route) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ describe('$route', function() {
|
|||
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/Book/:book/Chapter/:chapter',
|
||||
{controller: noop, template: 'Chapter.html'});
|
||||
{controller: noop, templateUrl: 'Chapter.html'});
|
||||
$routeProvider.when('/Blank', {});
|
||||
});
|
||||
inject(function($route, $location, $rootScope) {
|
||||
|
|
@ -62,7 +62,7 @@ describe('$route', function() {
|
|||
|
||||
it('should match a route that contains special chars in the path', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/$test.23/foo(bar)/:baz', {template: 'test.html'});
|
||||
$routeProvider.when('/$test.23/foo(bar)/:baz', {templateUrl: 'test.html'});
|
||||
});
|
||||
inject(function($route, $location, $rootScope) {
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ describe('$route', function() {
|
|||
|
||||
it('should change route even when only search param changes', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/test', {template: 'test.html'});
|
||||
$routeProvider.when('/test', {templateUrl: 'test.html'});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
|
|
@ -108,7 +108,7 @@ describe('$route', function() {
|
|||
|
||||
it('should allow routes to be defined with just templates without controllers', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo', {template: 'foo.html'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'foo.html'});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
|
|
@ -121,7 +121,7 @@ describe('$route', function() {
|
|||
$location.path('/foo');
|
||||
$rootScope.$digest();
|
||||
|
||||
expect($route.current.template).toEqual('foo.html');
|
||||
expect($route.current.templateUrl).toEqual('foo.html');
|
||||
expect($route.current.controller).toBeUndefined();
|
||||
expect(onChangeSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
|
@ -132,8 +132,8 @@ describe('$route', function() {
|
|||
function NotFoundCtrl() {}
|
||||
|
||||
module(function($routeProvider){
|
||||
$routeProvider.when('/foo', {template: 'foo.html'});
|
||||
$routeProvider.otherwise({template: '404.html', controller: NotFoundCtrl});
|
||||
$routeProvider.when('/foo', {templateUrl: 'foo.html'});
|
||||
$routeProvider.otherwise({templateUrl: '404.html', controller: NotFoundCtrl});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
|
|
@ -146,7 +146,7 @@ describe('$route', function() {
|
|||
$location.path('/unknownRoute');
|
||||
$rootScope.$digest();
|
||||
|
||||
expect($route.current.template).toBe('404.html');
|
||||
expect($route.current.templateUrl).toBe('404.html');
|
||||
expect($route.current.controller).toBe(NotFoundCtrl);
|
||||
expect(onChangeSpy).toHaveBeenCalled();
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ describe('$route', function() {
|
|||
$location.path('/foo');
|
||||
$rootScope.$digest();
|
||||
|
||||
expect($route.current.template).toEqual('foo.html');
|
||||
expect($route.current.templateUrl).toEqual('foo.html');
|
||||
expect($route.current.controller).toBeUndefined();
|
||||
expect(onChangeSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
|
@ -163,18 +163,18 @@ describe('$route', function() {
|
|||
|
||||
it('should chain whens and otherwise', function() {
|
||||
module(function($routeProvider){
|
||||
$routeProvider.when('/foo', {template: 'foo.html'}).
|
||||
otherwise({template: 'bar.html'}).
|
||||
when('/baz', {template: 'baz.html'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'foo.html'}).
|
||||
otherwise({templateUrl: 'bar.html'}).
|
||||
when('/baz', {templateUrl: 'baz.html'});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
$rootScope.$digest();
|
||||
expect($route.current.template).toBe('bar.html');
|
||||
expect($route.current.templateUrl).toBe('bar.html');
|
||||
|
||||
$location.url('/baz');
|
||||
$rootScope.$digest();
|
||||
expect($route.current.template).toBe('baz.html');
|
||||
expect($route.current.templateUrl).toBe('baz.html');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -209,7 +209,7 @@ describe('$route', function() {
|
|||
deferB = $q.defer();
|
||||
return deferB.promise;
|
||||
});
|
||||
$routeProvider.when('/path', { template: 'foo.html', resolve: {
|
||||
$routeProvider.when('/path', { templateUrl: 'foo.html', resolve: {
|
||||
a: function($q) {
|
||||
deferA = $q.defer();
|
||||
return deferA.promise;
|
||||
|
|
@ -253,13 +253,8 @@ describe('$route', function() {
|
|||
inject(function($location, $route, $rootScope) {
|
||||
var log = '';
|
||||
|
||||
<<<<<<< HEAD
|
||||
$rootScope.$on('$beforeRouteChange', function() { log += 'before();'; });
|
||||
$rootScope.$on('$routeChangeError', function(e, n, l, reason) { log += 'failed(' + reason + ');'; });
|
||||
=======
|
||||
$rootScope.$on('$routeChangeStart', function() { log += 'before();'; });
|
||||
$rootScope.$on('$routeChangeFailed', function(e, n, l, reason) { log += 'failed(' + reason + ');'; });
|
||||
>>>>>>> ebebe46... chore($route): rename events
|
||||
$rootScope.$on('$routeChangeError', function(e, n, l, reason) { log += 'failed(' + reason + ');'; });
|
||||
|
||||
$location.path('/path');
|
||||
$rootScope.$digest();
|
||||
|
|
@ -275,14 +270,14 @@ describe('$route', function() {
|
|||
it('should fetch templates', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.
|
||||
when('/r1', { template: 'r1.html' }).
|
||||
when('/r2', { template: 'r2.html' });
|
||||
when('/r1', { templateUrl: 'r1.html' }).
|
||||
when('/r2', { templateUrl: 'r2.html' });
|
||||
});
|
||||
|
||||
inject(function($route, $httpBackend, $location, $rootScope) {
|
||||
var log = '';
|
||||
$rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.template + ');'});
|
||||
$rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.template + ');'});
|
||||
$rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.templateUrl + ');'});
|
||||
$rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.templateUrl + ');'});
|
||||
|
||||
$httpBackend.expectGET('r1.html').respond('R1');
|
||||
$httpBackend.expectGET('r2.html').respond('R2');
|
||||
|
|
@ -305,8 +300,8 @@ describe('$route', function() {
|
|||
it('should not update $routeParams until $routeChangeSuccess', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.
|
||||
when('/r1/:id', { template: 'r1.html' }).
|
||||
when('/r2/:id', { template: 'r2.html' });
|
||||
when('/r1/:id', { templateUrl: 'r1.html' }).
|
||||
when('/r2/:id', { templateUrl: 'r2.html' });
|
||||
});
|
||||
|
||||
inject(function($route, $httpBackend, $location, $rootScope, $routeParams) {
|
||||
|
|
@ -337,14 +332,14 @@ describe('$route', function() {
|
|||
it('should drop in progress route change when new route change occurs', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.
|
||||
when('/r1', { template: 'r1.html' }).
|
||||
when('/r2', { template: 'r2.html' });
|
||||
when('/r1', { templateUrl: 'r1.html' }).
|
||||
when('/r2', { templateUrl: 'r2.html' });
|
||||
});
|
||||
|
||||
inject(function($route, $httpBackend, $location, $rootScope) {
|
||||
var log = '';
|
||||
$rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.template + ');'});
|
||||
$rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.template + ');'});
|
||||
$rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.templateUrl + ');'});
|
||||
$rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.templateUrl + ');'});
|
||||
|
||||
$httpBackend.expectGET('r1.html').respond('R1');
|
||||
$httpBackend.expectGET('r2.html').respond('R2');
|
||||
|
|
@ -421,30 +416,30 @@ describe('$route', function() {
|
|||
|
||||
it('should match route with and without trailing slash', function() {
|
||||
module(function($routeProvider){
|
||||
$routeProvider.when('/foo', {template: 'foo.html'});
|
||||
$routeProvider.when('/bar/', {template: 'bar.html'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'foo.html'});
|
||||
$routeProvider.when('/bar/', {templateUrl: 'bar.html'});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
$location.path('/foo');
|
||||
$rootScope.$digest();
|
||||
expect($location.path()).toBe('/foo');
|
||||
expect($route.current.template).toBe('foo.html');
|
||||
expect($route.current.templateUrl).toBe('foo.html');
|
||||
|
||||
$location.path('/foo/');
|
||||
$rootScope.$digest();
|
||||
expect($location.path()).toBe('/foo');
|
||||
expect($route.current.template).toBe('foo.html');
|
||||
expect($route.current.templateUrl).toBe('foo.html');
|
||||
|
||||
$location.path('/bar');
|
||||
$rootScope.$digest();
|
||||
expect($location.path()).toBe('/bar/');
|
||||
expect($route.current.template).toBe('bar.html');
|
||||
expect($route.current.templateUrl).toBe('bar.html');
|
||||
|
||||
$location.path('/bar/');
|
||||
$rootScope.$digest();
|
||||
expect($location.path()).toBe('/bar/');
|
||||
expect($route.current.template).toBe('bar.html');
|
||||
expect($route.current.templateUrl).toBe('bar.html');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -453,10 +448,10 @@ describe('$route', function() {
|
|||
it('should support redirection via redirectTo property by updating $location', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/', {redirectTo: '/foo'});
|
||||
$routeProvider.when('/foo', {template: 'foo.html'});
|
||||
$routeProvider.when('/bar', {template: 'bar.html'});
|
||||
$routeProvider.when('/foo', {templateUrl: 'foo.html'});
|
||||
$routeProvider.when('/bar', {templateUrl: 'bar.html'});
|
||||
$routeProvider.when('/baz', {redirectTo: '/bar'});
|
||||
$routeProvider.otherwise({template: '404.html'});
|
||||
$routeProvider.otherwise({templateUrl: '404.html'});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
|
|
@ -469,14 +464,14 @@ describe('$route', function() {
|
|||
$location.path('/');
|
||||
$rootScope.$digest();
|
||||
expect($location.path()).toBe('/foo');
|
||||
expect($route.current.template).toBe('foo.html');
|
||||
expect($route.current.templateUrl).toBe('foo.html');
|
||||
expect(onChangeSpy.callCount).toBe(2);
|
||||
|
||||
onChangeSpy.reset();
|
||||
$location.path('/baz');
|
||||
$rootScope.$digest();
|
||||
expect($location.path()).toBe('/bar');
|
||||
expect($route.current.template).toBe('bar.html');
|
||||
expect($route.current.templateUrl).toBe('bar.html');
|
||||
expect(onChangeSpy.callCount).toBe(2);
|
||||
});
|
||||
});
|
||||
|
|
@ -485,7 +480,7 @@ describe('$route', function() {
|
|||
it('should interpolate route vars in the redirected path from original path', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo/:id/foo/:subid/:extraId', {redirectTo: '/bar/:id/:subid/23'});
|
||||
$routeProvider.when('/bar/:id/:subid/:subsubid', {template: 'bar.html'});
|
||||
$routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
|
|
@ -494,14 +489,14 @@ describe('$route', function() {
|
|||
|
||||
expect($location.path()).toEqual('/bar/id1/subid3/23');
|
||||
expect($location.search()).toEqual({extraId: 'gah'});
|
||||
expect($route.current.template).toEqual('bar.html');
|
||||
expect($route.current.templateUrl).toEqual('bar.html');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should interpolate route vars in the redirected path from original search', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/bar/:id/:subid/:subsubid', {template: 'bar.html'});
|
||||
$routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'});
|
||||
$routeProvider.when('/foo/:id/:extra', {redirectTo: '/bar/:id/:subid/99'});
|
||||
});
|
||||
|
||||
|
|
@ -511,7 +506,7 @@ describe('$route', function() {
|
|||
|
||||
expect($location.path()).toEqual('/bar/id3/sid1/99');
|
||||
expect($location.search()).toEqual({appended: 'true', extra: 'eId'});
|
||||
expect($route.current.template).toEqual('bar.html');
|
||||
expect($route.current.templateUrl).toEqual('bar.html');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -525,7 +520,7 @@ describe('$route', function() {
|
|||
}
|
||||
|
||||
module(function($routeProvider){
|
||||
$routeProvider.when('/bar/:id/:subid/:subsubid', {template: 'bar.html'});
|
||||
$routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'});
|
||||
$routeProvider.when('/foo/:id', {redirectTo: customRedirectFn});
|
||||
});
|
||||
|
||||
|
|
@ -540,7 +535,7 @@ describe('$route', function() {
|
|||
|
||||
it('should replace the url when redirecting', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/bar/:id', {template: 'bar.html'});
|
||||
$routeProvider.when('/bar/:id', {templateUrl: 'bar.html'});
|
||||
$routeProvider.when('/foo/:id/:extra', {redirectTo: '/bar/:id'});
|
||||
});
|
||||
inject(function($route, $location, $rootScope) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue