Created
May 14, 2015 18:32
-
-
Save benoror/e7958edc34820d2b5e4d to your computer and use it in GitHub Desktop.
input addon with templateManipulator (doesn't work)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.run(function config(formlyConfig) { | |
formlyConfig.templateManipulators.preWrapper.push(function(template, options, scope) { | |
var heritage = getHeritage(options.type); | |
if (heritage.indexOf('money') !== -1) { | |
console.log(options) | |
options.templateOptions.addonLeft = { | |
text: '$' | |
} | |
return 'THIS IS AN INPUT!' + template; | |
} | |
return template; | |
}); | |
function getHeritage(parent) { | |
var heritage = []; | |
var type; | |
while(parent) { | |
heritage.push(parent); | |
type = formlyConfig.getType(parent); | |
parent = type.extends; | |
} | |
return heritage; | |
} | |
}) | |
.config(function config(formlyConfigProvider) { | |
/* | |
money | |
Extends input template | |
*/ | |
formlyConfigProvider.setType({ | |
name: 'money', | |
extends: 'input' | |
}); | |
/* | |
async_select | |
Extends select template | |
*/ | |
formlyConfigProvider.setType({ | |
name: 'async_select', | |
extends: 'select', | |
defaultOptions: { | |
templateOptions: { | |
options: [], | |
valueProp: "value", | |
labelProp: "label", | |
}, | |
controller: /* @ngInject */ function($scope, CRUDService) { | |
$scope.to.loading = CRUDService.options($scope.to.params).then(function(res) { | |
$scope.to.options = res; | |
// note, the line above is shorthand for: | |
// $scope.options.templateOptions.options = data; | |
return res; | |
}); | |
} | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment