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

Commit 70ebce4

Browse files
author
Kent C. Dodds
committed
Grunt build
1 parent c1850a0 commit 70ebce4

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

dist/formly.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,24 @@ angular.module('formly.render').directive('formlyField', [
5454
value: '=formValue'
5555
},
5656
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);
6460
} 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);
6675
}
6776
},
6877
controller: [
@@ -72,8 +81,14 @@ angular.module('formly.render').directive('formlyField', [
7281
if (typeof $scope.options.default !== 'undefined') {
7382
$scope.value = $scope.options.default;
7483
}
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+
}
7590
// 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;
7792
}
7893
]
7994
};

dist/formly.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formly.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)