mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-22 10:49:24 +08:00
feat(route): Allow using functions as template params in 'when'
This commit is contained in:
committed by
Misko Hevery
parent
b8bd4d5460
commit
faf02f0c4d
@@ -715,6 +715,53 @@ describe('$route', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should allow using a function as a template', function() {
|
||||
var customTemplateWatcher = jasmine.createSpy('customTemplateWatcher');
|
||||
|
||||
function customTemplateFn(routePathParams) {
|
||||
customTemplateWatcher(routePathParams);
|
||||
expect(routePathParams).toEqual({id: 'id3'});
|
||||
return '<h1>' + routePathParams.id + '</h1>';
|
||||
}
|
||||
|
||||
module(function($routeProvider){
|
||||
$routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'});
|
||||
$routeProvider.when('/foo/:id', {template: customTemplateFn});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
$location.path('/foo/id3');
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(customTemplateWatcher).toHaveBeenCalledWith({id: 'id3'});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should allow using a function as a templateUrl', function() {
|
||||
var customTemplateUrlWatcher = jasmine.createSpy('customTemplateUrlWatcher');
|
||||
|
||||
function customTemplateUrlFn(routePathParams) {
|
||||
customTemplateUrlWatcher(routePathParams);
|
||||
expect(routePathParams).toEqual({id: 'id3'});
|
||||
return 'foo.html';
|
||||
}
|
||||
|
||||
module(function($routeProvider){
|
||||
$routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'});
|
||||
$routeProvider.when('/foo/:id', {templateUrl: customTemplateUrlFn});
|
||||
});
|
||||
|
||||
inject(function($route, $location, $rootScope) {
|
||||
$location.path('/foo/id3');
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(customTemplateUrlWatcher).toHaveBeenCalledWith({id: 'id3'});
|
||||
expect($route.current.loadedTemplateUrl).toEqual('foo.html');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('reload', function() {
|
||||
|
||||
it('should reload even if reloadOnSearch is false', function() {
|
||||
|
||||
Reference in New Issue
Block a user