angular.module("bootstrap-custom", []).directive('button', function() {
    return {
        restrict: "E",
        require: "ngModel",
        link: function($scope, element, attr, ctrl){
            if(element.parent('[data-toggle="buttons-checkbox"].btn-group').length){
                return
            }
            
            $scope.$watch(attr.ngModel, function(newValue, oldValue){
                element.toggleClass('active', ctrl.$viewValue);
            })
            
            element.bind('click', function(e){
                $scope.$apply(function(scope){
                    ctrl.$setViewValue(!ctrl.$viewValue);
                })
                e.stopPropagation();
            })
        }
    }
})