Skip to content

Instantly share code, notes, and snippets.

@shadda
Created May 13, 2014 21:21
Show Gist options
  • Select an option

  • Save shadda/fcd1360146d466aa5df2 to your computer and use it in GitHub Desktop.

Select an option

Save shadda/fcd1360146d466aa5df2 to your computer and use it in GitHub Desktop.
PerfDB.app.directive('collection', function ($compile)
{
return {
restrict: 'A',
replace: true,
require: '?ngModel',
scope: {
collection: '='
},
link: function($scope, $element, $attr, $ngModel)
{
if(Object.size($scope.collection.categories) > 0)
{
$compile('<optgroup class="collection" label="{{category.name}}" collection="category" ng-repeat="category in collection.categories"></optgroup>')($scope, function(cloned, scope)
{
$element.append(cloned);
});
}
if($scope.collection.children != undefined && $scope.collection.children.length)
{
$compile('<optgroup label="{{data.name}}" class="collection" leaf="child" ng-repeat="child in collection.children"></optgroup>')($scope, function(cloned, scope)
{
$element.append(cloned);
});
}
}
}
});
PerfDB.app.directive('leaf', function($compile)
{
return {
restrict: 'A',
replace: true,
scope: {
leaf: '='
},
link: function($scope, $element, $attrs)
{
$compile('<option class="leaf" value="{{leaf.id}}">{{leaf.name}}</option>')($scope, function(cloned, scope)
{
$element.replaceWith(cloned);
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment