@@ -54,15 +54,24 @@ angular.module('formly.render').directive('formlyField', [
54
54
value : '=formValue'
55
55
} ,
56
56
link : function fieldLink ( $scope , $element , $attr ) {
57
- var templateUrl = $scope . options . templateUrl || getTemplateUrl ( $scope . options . type ) ;
58
- if ( templateUrl ) {
59
- $http . get ( templateUrl , { cache : $templateCache } ) . success ( function ( data ) {
60
- //template data returned
61
- $element . html ( data ) ;
62
- $compile ( $element . contents ( ) ) ( $scope ) ;
63
- } ) ;
57
+ var template = $scope . options . template ;
58
+ if ( template ) {
59
+ setElementTemplate ( template ) ;
64
60
} else {
65
- console . log ( 'Formly Error: template type \'' + $scope . options . type + '\' not supported.' ) ;
61
+ var templateUrl = $scope . options . templateUrl || getTemplateUrl ( $scope . options . type ) ;
62
+ if ( templateUrl ) {
63
+ $http . get ( templateUrl , { cache : $templateCache } ) . then ( function ( response ) {
64
+ setElementTemplate ( response . data ) ;
65
+ } , function ( error ) {
66
+ console . log ( 'Formly Error: Problem loading template for ' + templateUrl , error ) ;
67
+ } ) ;
68
+ } else {
69
+ console . log ( 'Formly Error: template type \'' + $scope . options . type + '\' not supported.' ) ;
70
+ }
71
+ }
72
+ function setElementTemplate ( templateData ) {
73
+ $element . html ( templateData ) ;
74
+ $compile ( $element . contents ( ) ) ( $scope ) ;
66
75
}
67
76
} ,
68
77
controller : [
@@ -72,8 +81,14 @@ angular.module('formly.render').directive('formlyField', [
72
81
if ( typeof $scope . options . default !== 'undefined' ) {
73
82
$scope . value = $scope . options . default ;
74
83
}
84
+ var type = $scope . options . type ;
85
+ if ( ! type && $scope . options . template ) {
86
+ type = 'template' ;
87
+ } else if ( ! type && $scope . options . templateUrl ) {
88
+ type = 'templateUrl' ;
89
+ }
75
90
// set field id to link labels and fields
76
- $scope . id = $scope . formId + $scope . options . type + $scope . index ;
91
+ $scope . id = $scope . formId + type + $scope . index ;
77
92
}
78
93
]
79
94
} ;
0 commit comments