diff --git a/src/router-directive.es5.js b/src/router-directive.es5.js index c19f120..7e8da96 100644 --- a/src/router-directive.es5.js +++ b/src/router-directive.es5.js @@ -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); diff --git a/test/router-viewport.es5.spec.js b/test/router-viewport.es5.spec.js index a2bbbeb..dcc4f06 100644 --- a/test/router-viewport.es5.spec.js +++ b/test/router-viewport.es5.spec.js @@ -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('
'); + + $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(''); + + $router.navigate('/t'); + $rootScope.$digest(); + expect(elt.text()).toBe('hi'); + })); it('should change location path', inject(function ($router, $location) {