From 2fa7bf63774d956a03341b8753554767bf2f4b34 Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Thu, 10 Dec 2015 01:51:19 +0200 Subject: [PATCH] fix(Module): allow passing template/templateUrl in array notation --- src/loader.js | 2 +- test/loaderSpec.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/loader.js b/src/loader.js index febead684002..30448b537724 100644 --- a/src/loader.js +++ b/src/loader.js @@ -362,7 +362,7 @@ function setupModuleLoader(window) { component: function(name, options) { function factory($injector) { function makeInjectable(fn) { - if (angular.isFunction(fn)) { + if (isFunction(fn) || Array.isArray(fn)) { return function(tElement, tAttrs) { return $injector.invoke(fn, this, {$element: tElement, $attrs: tAttrs}); }; diff --git a/test/loaderSpec.js b/test/loaderSpec.js index 3204cf27b4a0..4595d3cb8dfc 100644 --- a/test/loaderSpec.js +++ b/test/loaderSpec.js @@ -174,6 +174,24 @@ describe('component', function() { }); }); + it('should allow passing injectable arrays as template/templateUrl', function() { + var log = ''; + window.angular.module('my', []).component('myComponent', { + template: ['$element', '$attrs', 'myValue', function($element, $attrs, myValue) { + log += 'template,' + $element + ',' + $attrs + ',' + myValue + '\n'; + }], + templateUrl: ['$element', '$attrs', 'myValue', function($element, $attrs, myValue) { + log += 'templateUrl,' + $element + ',' + $attrs + ',' + myValue + '\n'; + }] + }).value('myValue', 'blah'); + module('my'); + inject(function(myComponentDirective) { + myComponentDirective[0].template('a', 'b'); + myComponentDirective[0].templateUrl('c', 'd'); + expect(log).toEqual('template,a,b,blah\ntemplateUrl,c,d,blah\n'); + }); + }); + it('should allow passing transclude as object', function() { window.angular.module('my', []).component('myComponent', { transclude: {}