Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

[feat] add ability to customize template by setting property on controller con... #157

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions src/router-directive.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,22 @@ function ngViewportDirective($animate, $compile, $controller, $templateRequest,
return !ctrl || !ctrl.canActivate || ctrl.canActivate(instruction);
},
load: function (instruction) {
var componentTemplateUrl = $componentLoader(getComponentName(instruction)).template;
return $templateRequest(componentTemplateUrl).then(function(templateHtml) {
var componentTemplateUrl, $template;
if (ctrl.constructor.$template) {
$template = ctrl.constructor.$template
if ($template.inline) {
myCtrl.$$template = $template.inline;
return;
} else {
componentTemplateUrl = $template.url;
}
} else {
componentTemplateUrl = $componentLoader(getComponentName(instruction)).template;
}
$templateRequest(componentTemplateUrl).then(function(templateHtml) {
myCtrl.$$template = templateHtml;
});
return;
},
activate: function (instruction) {
var componentName = getComponentName(instruction);
Expand Down
32 changes: 32 additions & 0 deletions test/router-viewport.es5.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,38 @@ describe('ngViewport', function () {
expect(elt.text()).toBe('hi');
}));

it('should load a seperate template when a controller has a $template property', inject(function ($router) {
$templateCache.put('NonStandardDirectory/aNonStandardName.html', [200, 'hi', {}]);
$controllerProvider.register('TemplateController', TemplateController);
function TemplateController() {}
TemplateController.$template = {
url: 'NonStandardDirectory/aNonStandardName.html'
}
$router.config([
{ path: '/t', component: 'template' }
]);
compile('<div ng-viewport></div>');

$router.navigate('/t');
$rootScope.$digest();
expect(elt.text()).toBe('hi');
}));

it('should load a seperate template when a controller has a $template property', inject(function ($router) {
$controllerProvider.register('InlineTemplateController', InlineTemplateController);
function InlineTemplateController() {}
InlineTemplateController.$template = {
inline: 'hi'
}
$router.config([
{ path: '/t', component: 'inlineTemplate' }
]);
compile('<div ng-viewport></div>');

$router.navigate('/t');
$rootScope.$digest();
expect(elt.text()).toBe('hi');
}));

it('should change location path', inject(function ($router, $location) {

Expand Down