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

Commit 2742d5d

Browse files
committed
moved provider to its own file
1 parent 64c1345 commit 2742d5d

File tree

8 files changed

+53
-49
lines changed

8 files changed

+53
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Version numbers correspond to `bower.json` version
44

55
## Features
66

7-
Adding the `formlyProvider` which allows developers to set templateUrls for types. Also allows them to make custom types.
7+
Adding the `formlyTemplateProvider` which allows developers to set templateUrls for types. Also allows them to make custom types.
88

99
## Bug Fixes
1010

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = function(grunt) {
3535
{
3636
expand: true,
3737
cwd: '<%= formlyConfig.base %>/',
38-
src: ['directives/formly*.*', 'modules/formly*.*', '!.jshintrc'],
38+
src: ['directives/formly*.*', 'modules/formly*.*', 'providers/formly*.*', '!.jshintrc'],
3939
dest: '.tmp/'
4040
}
4141
]
@@ -52,7 +52,7 @@ module.exports = function(grunt) {
5252
concat: {
5353
build: {
5454
// specifing files so that they are added in this order
55-
src: ['.tmp/modules/formly*.js', '.tmp/directives/formly*.js', '.tmp/formly*.js'],
55+
src: ['.tmp/modules/formly*.js', '.tmp/directives/formly*.js', '.tmp/providers/formly*.js', '.tmp/formly*.js'],
5656
dest: '.tmp/formly.js'
5757
}
5858
},

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,19 @@ _Example password field_
400400

401401
### Global Config
402402

403-
You can configure formly to use custom templates for specified types (your own "text" template) by injecting the `formlyProvider` in your app's `config` function. The `formlyProvider` has the following functions:
403+
You can configure formly to use custom templates for specified types (your own "text" template) by injecting the `formlyTemplateProvider` in your app's `config` function. The `formlyTemplateProvider` has the following functions:
404404

405405
#### setTemplateUrl
406406

407407
Allows you to set a template
408408

409409
```javascript
410-
formlyProvider.setTemplateUrl('radio', 'views/custom-formly-radio.html');
411-
formlyProvider.setTemplateUrl('checkbox', 'views/custom-formly-checkbox.html');
410+
formlyTemplateProvider.setTemplateUrl('radio', 'views/custom-formly-radio.html');
411+
formlyTemplateProvider.setTemplateUrl('checkbox', 'views/custom-formly-checkbox.html');
412412

413413
// the same can be accomplished with
414414

415-
formlyProvider.setTemplate({
415+
formlyTemplateProvider.setTemplate({
416416
radio: 'views/custom-formly-radio.html',
417417
checkbox: 'views/custom-formly-checkbox.html'
418418
});
@@ -423,8 +423,8 @@ formlyProvider.setTemplate({
423423
Allows you to get the template
424424

425425
```javascript
426-
formlyProvider.setTemplateUrl('foo', 'bar');
427-
formlyProvider.getTemplateUrl('foo') === 'bar'; // true
426+
formlyTemplateProvider.setTemplateUrl('radio', 'views/custom-formly-radio.html');
427+
formlyTemplateProvider.getTemplateUrl('radio') === 'views/custom-formly-radio.html'; // true
428428
```
429429

430430
## Roadmap

src/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var app = angular.module('app', ['ng',
88

99
app.constant('usingCustomTypeTemplates', window.localStorage.getItem('useCustomTypeTemplates') === 'true');
1010

11-
app.config(function($stateProvider, $urlRouterProvider, $locationProvider, formlyProvider, usingCustomTypeTemplates) {
11+
app.config(function($stateProvider, $urlRouterProvider, $locationProvider, formlyTemplateProvider, usingCustomTypeTemplates) {
1212
$locationProvider.html5Mode(false);
1313
$locationProvider.hashPrefix('!');
1414

@@ -21,9 +21,9 @@ app.config(function($stateProvider, $urlRouterProvider, $locationProvider, forml
2121
controller: 'home'
2222
});
2323
if (usingCustomTypeTemplates) {
24-
formlyProvider.setTemplateUrl('text', 'views/custom-field-text.html');
24+
formlyTemplateProvider.setTemplateUrl('text', 'views/custom-field-text.html');
2525
// or
26-
formlyProvider.setTemplateUrl({
26+
formlyTemplateProvider.setTemplateUrl({
2727
radio: 'views/custom-field-radio.html',
2828
checkbox: 'views/custom-field-checkbox.html'
2929
});

src/directives/formly-field.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
angular.module('formly.render')
3-
.directive('formlyField', function formlyField($http, $compile, $templateCache, formly) {
3+
.directive('formlyField', function formlyField($http, $compile, $templateCache, formlyTemplate) {
44
return {
55
restrict: 'AE',
66
transclude: true,
@@ -15,7 +15,7 @@ angular.module('formly.render')
1515
if (template) {
1616
setElementTemplate(template);
1717
} else {
18-
var templateUrl = $scope.options.templateUrl || formly.getTemplateUrl($scope.options.type);
18+
var templateUrl = $scope.options.templateUrl || formlyTemplate.getTemplateUrl($scope.options.type);
1919
if (templateUrl) {
2020
$http.get(templateUrl, {
2121
cache: $templateCache

src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@
4040
<script src="modules/formly-render.js"></script>
4141
<script src="directives/formly-form.js"></script>
4242
<script src="directives/formly-field.js"></script>
43+
<script src="providers/formly-template.js"></script>
4344
</body>
4445
</html>

src/modules/formly-render.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,2 @@
11
// Render module for formly to display forms
2-
angular.module('formly.render', []).provider('formly', function() {
3-
4-
var templateMap = {
5-
textarea: 'directives/formly-field-textarea.html',
6-
radio: 'directives/formly-field-radio.html',
7-
select: 'directives/formly-field-select.html',
8-
number: 'directives/formly-field-number.html',
9-
checkbox: 'directives/formly-field-checkbox.html',
10-
password: 'directives/formly-field-password.html',
11-
hidden: 'directives/formly-field-hidden.html',
12-
email: 'directives/formly-field-email.html',
13-
text: 'directives/formly-field-text.html'
14-
};
15-
16-
function setTemplateUrl(name, templateUrl) {
17-
if (typeof name === 'string') {
18-
templateMap[name] = templateUrl;
19-
} else {
20-
angular.forEach(name, function(templateUrl, name) {
21-
setTemplateUrl(name, templateUrl)
22-
});
23-
}
24-
}
25-
26-
function getTemplateUrl(type) {
27-
return templateMap[type];
28-
};
29-
30-
this.setTemplateUrl = setTemplateUrl;
31-
this.getTemplateUrl = getTemplateUrl;
32-
this.$get = function formly() {
33-
return this;
34-
}
35-
36-
});
2+
angular.module('formly.render', []);

src/providers/formly-template.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
angular.module('formly.render')
3+
.provider('formlyTemplate', function() {
4+
5+
var templateMap = {
6+
textarea: 'directives/formly-field-textarea.html',
7+
radio: 'directives/formly-field-radio.html',
8+
select: 'directives/formly-field-select.html',
9+
number: 'directives/formly-field-number.html',
10+
checkbox: 'directives/formly-field-checkbox.html',
11+
password: 'directives/formly-field-password.html',
12+
hidden: 'directives/formly-field-hidden.html',
13+
email: 'directives/formly-field-email.html',
14+
text: 'directives/formly-field-text.html'
15+
};
16+
17+
function setTemplateUrl(name, templateUrl) {
18+
if (typeof name === 'string') {
19+
templateMap[name] = templateUrl;
20+
} else {
21+
angular.forEach(name, function(templateUrl, name) {
22+
setTemplateUrl(name, templateUrl)
23+
});
24+
}
25+
}
26+
27+
function getTemplateUrl(type) {
28+
return templateMap[type];
29+
};
30+
31+
this.setTemplateUrl = setTemplateUrl;
32+
this.getTemplateUrl = getTemplateUrl;
33+
this.$get = function formlyTemplate() {
34+
return this;
35+
}
36+
37+
});

0 commit comments

Comments
 (0)