Skip to content

Instantly share code, notes, and snippets.

@shadda
Forked from brendanmckenzie/gist:2510f8e009641a50ad91
Last active August 29, 2015 14:08
Show Gist options
  • Save shadda/a4313577211a9c17253b to your computer and use it in GitHub Desktop.
Save shadda/a4313577211a9c17253b to your computer and use it in GitHub Desktop.
(function (window) {
'use strict';
function ReferenceSelector(ReferenceSvc, $compile) {
var directive = {
restrict: 'A',
replace: false,
transclude: true,
require: '^?ngModel'
};
directive.link = function (scope, element, attrs, ngModel) {
ReferenceSvc.get(attrs.type, function (data) {
scope.options = data;
});
if(ngModel && attr.type)
{
ngModel.$parsers.push(function(viewValue)
{
return scope.options[viewValue];
})
}
$(element).attr('ng-options', 'a.id as a.displayText for a in options');
$compile($(element).contents())(scope, function(cloned, _scope)
{
element.replace(cloned);
});
}
return directive;
}
window.app.directive('referenceSelector', ['ReferenceSvc', '$compile', ReferenceSelector]);
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment