Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 99d601a

Browse files
Shahar Talmilgalfaso
Shahar Talmi
authored andcommitted
fix(Module): allow passing template/templateUrl in array notation
Close: #13485
1 parent a6e9174 commit 99d601a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ function setupModuleLoader(window) {
405405
component: function(name, options) {
406406
function factory($injector) {
407407
function makeInjectable(fn) {
408-
if (angular.isFunction(fn)) {
408+
if (isFunction(fn) || Array.isArray(fn)) {
409409
return function(tElement, tAttrs) {
410410
return $injector.invoke(fn, this, {$element: tElement, $attrs: tAttrs});
411411
};

test/loaderSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ describe('component', function() {
174174
});
175175
});
176176

177+
it('should allow passing injectable arrays as template/templateUrl', function() {
178+
var log = '';
179+
window.angular.module('my', []).component('myComponent', {
180+
template: ['$element', '$attrs', 'myValue', function($element, $attrs, myValue) {
181+
log += 'template,' + $element + ',' + $attrs + ',' + myValue + '\n';
182+
}],
183+
templateUrl: ['$element', '$attrs', 'myValue', function($element, $attrs, myValue) {
184+
log += 'templateUrl,' + $element + ',' + $attrs + ',' + myValue + '\n';
185+
}]
186+
}).value('myValue', 'blah');
187+
module('my');
188+
inject(function(myComponentDirective) {
189+
myComponentDirective[0].template('a', 'b');
190+
myComponentDirective[0].templateUrl('c', 'd');
191+
expect(log).toEqual('template,a,b,blah\ntemplateUrl,c,d,blah\n');
192+
});
193+
});
194+
177195
it('should allow passing transclude as object', function() {
178196
window.angular.module('my', []).component('myComponent', {
179197
transclude: {}

0 commit comments

Comments
 (0)