@@ -7,43 +7,8 @@ angular.module('formly.render').directive('formlyField', [
7
7
'$http' ,
8
8
'$compile' ,
9
9
'$templateCache' ,
10
- function formlyField ( $http , $compile , $templateCache ) {
11
- var getTemplateUrl = function ( type ) {
12
- var templateUrl = '' ;
13
- switch ( type ) {
14
- case 'textarea' :
15
- templateUrl = 'directives/formly-field-textarea.html' ;
16
- break ;
17
- case 'radio' :
18
- templateUrl = 'directives/formly-field-radio.html' ;
19
- break ;
20
- case 'select' :
21
- templateUrl = 'directives/formly-field-select.html' ;
22
- break ;
23
- case 'number' :
24
- templateUrl = 'directives/formly-field-number.html' ;
25
- break ;
26
- case 'checkbox' :
27
- templateUrl = 'directives/formly-field-checkbox.html' ;
28
- break ;
29
- case 'password' :
30
- templateUrl = 'directives/formly-field-password.html' ;
31
- break ;
32
- case 'hidden' :
33
- templateUrl = 'directives/formly-field-hidden.html' ;
34
- break ;
35
- case 'email' :
36
- templateUrl = 'directives/formly-field-email.html' ;
37
- break ;
38
- case 'text' :
39
- templateUrl = 'directives/formly-field-text.html' ;
40
- break ;
41
- default :
42
- templateUrl = null ;
43
- break ;
44
- }
45
- return templateUrl ;
46
- } ;
10
+ 'formlyTemplate' ,
11
+ function formlyField ( $http , $compile , $templateCache , formlyTemplate ) {
47
12
return {
48
13
restrict : 'AE' ,
49
14
transclude : true ,
@@ -58,7 +23,7 @@ angular.module('formly.render').directive('formlyField', [
58
23
if ( template ) {
59
24
setElementTemplate ( template ) ;
60
25
} else {
61
- var templateUrl = $scope . options . templateUrl || getTemplateUrl ( $scope . options . type ) ;
26
+ var templateUrl = $scope . options . templateUrl || formlyTemplate . getTemplateUrl ( $scope . options . type ) ;
62
27
if ( templateUrl ) {
63
28
$http . get ( templateUrl , { cache : $templateCache } ) . then ( function ( response ) {
64
29
setElementTemplate ( response . data ) ;
@@ -132,6 +97,38 @@ angular.module('formly.render').directive('formlyForm', function formlyForm() {
132
97
]
133
98
} ;
134
99
} ) ;
100
+ 'use strict' ;
101
+ angular . module ( 'formly.render' ) . provider ( 'formlyTemplate' , function ( ) {
102
+ var templateMap = {
103
+ textarea : 'directives/formly-field-textarea.html' ,
104
+ radio : 'directives/formly-field-radio.html' ,
105
+ select : 'directives/formly-field-select.html' ,
106
+ number : 'directives/formly-field-number.html' ,
107
+ checkbox : 'directives/formly-field-checkbox.html' ,
108
+ password : 'directives/formly-field-password.html' ,
109
+ hidden : 'directives/formly-field-hidden.html' ,
110
+ email : 'directives/formly-field-email.html' ,
111
+ text : 'directives/formly-field-text.html'
112
+ } ;
113
+ function setTemplateUrl ( name , templateUrl ) {
114
+ if ( typeof name === 'string' ) {
115
+ templateMap [ name ] = templateUrl ;
116
+ } else {
117
+ angular . forEach ( name , function ( templateUrl , name ) {
118
+ setTemplateUrl ( name , templateUrl ) ;
119
+ } ) ;
120
+ }
121
+ }
122
+ function getTemplateUrl ( type ) {
123
+ return templateMap [ type ] ;
124
+ }
125
+ ;
126
+ this . setTemplateUrl = setTemplateUrl ;
127
+ this . getTemplateUrl = getTemplateUrl ;
128
+ this . $get = function formlyTemplate ( ) {
129
+ return this ;
130
+ } ;
131
+ } ) ;
135
132
angular . module ( 'formly.render' ) . run ( [
136
133
'$templateCache' ,
137
134
function ( $templateCache ) {
0 commit comments