Angular: Empty Fiddle

http://angularjs.org/

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js"></script>

JavaScript

var myApp = angular.module('myApp', []);

app.directive('categories', function (Categories) {
    return {
        restrict: 'A',
        scope: {
            selectedCategories: '=',
            buttonText: '='
        },
        link: function (scope, element, attrs) {
            element.bind('click', function () {
                Categories.modal(function (categories) {
                    var filtered = _.filter(categories, function (c) {
                        return (c.selected == true)
                    });
                    scope.$apply(function () {
                        scope.selected = _.pluck(filtered, 'id');
                    });
                });
            });
        }

    }
});