So I've looked at many other questions like this and haven't found one that quite seems to cover what I'm trying to do.
I'm using a template in a directive to create a custom dropdown with fancy stuff like a search box. For this, I have to use template; I can't just use compile with element.replaceWith (I'm able to get this working if I use compile with an attrs param, but then the custom template doesn't work).
All I want to do is select a particular array of options depending on the contents of an attribute in my custom tag:
HTML: <customdropdown useoptionset="first"></customdropdown>
JS:
angular.module('ui.bootstrap', [])
.constant('customdropdownConfig', {
//bunch of properties here
})
.directive('customdropdown ', ['$parse', 'customdropdownConfig', function ($compile, customdropdownConfig) {
return {
restrict: 'EA',
replace: true,
template: (function(conf) {
var optionset = //how can i access the useoptionset attribute here?
var options = //stuff involving useoptionset and conf
return '<select ui-select="customDropdown">' + options + '</select>';
}(customdropdownConfig))
};
}])
It seems to me that this should be a very common and obvious use case, but maybe I'm missing something about how Angular works.