Forked from brendanmckenzie/gist:2510f8e009641a50ad91
Last active
August 29, 2015 14:08
-
-
Save shadda/a4313577211a9c17253b to your computer and use it in GitHub Desktop.
This file contains 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
(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