Skip to content

Instantly share code, notes, and snippets.

@garciadanny
Created November 10, 2014 03:35
Show Gist options
  • Save garciadanny/98acda3462f3edf89c16 to your computer and use it in GitHub Desktop.
Save garciadanny/98acda3462f3edf89c16 to your computer and use it in GitHub Desktop.
BlogPost: AngularJS Custom Directives
...
myApp.directive('selectFilter', ['$compile', function($compile) {
return {
restrict: 'E',
link: function(scope, element, attrs) {
var model = attrs.model;
var modelList = pluralize(model);
var attribute = attrs.attribute;
var jadeString = "select(ng-model='#{attribute}', ng-options=\"#{model}.#{attribute} as #{model}.#{attribute} for #{model} in #{modelList} | unique:'#{attribute}'\")" + "\n\toption(value='') All";
var jadeTemplate = jade.compile(jadeString);
var html = jadeTemplate({model: model, attribute: attribute, modelList: modelList});
var c = $compile(html)(scope);
element.append(c);
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment