2

I'm having a problem how to solve to implement buttons refresh (enable/disable) without using ng-disabled and ng-click

I've send to my directive the following configuration (one or more buttons)

buttonsConfig() {
  var button1 = {
    icon: '<i class="fa fa-check"></i>',
    name: button,
    actionEvent: () => { this.openConfirm(); },
    order: 1,
    active: false,
    large: true
    }
}

Here it is how I made dynamically HTML and check the confing file of disabled/enabled button(s)

link: ng.IDirectiveLinkFn = ($scope: IActionBarScope, $element: ng.IAugmentedJQuery, $attrs: ng.IAttributes) => {
            var navbar = this.drawActionBar($scope.config);

            var padder = angular.element('<div id="padder" ng-if="action.isOpen"></div>');
            this.$compile(navbar)($scope);
            this.$compile(padder)($scope);

            $element.append(navbar, padder);
                }

        setupButtonActions(element: ng.IAugmentedJQuery, config) {
            if (config.actionEvent != null) {
                if (config.active === false) { //skip undefined or true
                    element.addClass("disabled");
                } else {
                    element.removeClass("disabled");
                    element.mouseup(config.actionEvent);
                }
            }
        }

in my directive I generate html buttons (small/large) on dynamical HTML grid (CSS), so I do not know how to bind that button is enabled/disabled.

Before used my directive I used:

<button ng-if="!ctrl.isReadOnly" type="submit" class="btn btn-flat btn-primary" ng-disabled="!ctrl.selectedAreReady()" ng-click="ctrl.openConfirm()"><i class="fa fa-check"></i> {{'button' | translate}}</button>

and it was all done static in html, without coding, so I sended through the ng-disabled=ctrl.selectedAreReady() that the button is enabled or not.

before checked(disabeled button) enter image description here

after checked (button is enabled) enter image description here

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Andrej
  • 828
  • 1
  • 15
  • 25

1 Answers1

0

If your dont want ng-disabled, you can use javascript related API.

document.getElementById("myBtn").disabled = true;

You can set it to false if you want to enable the button back again

Pramod_Para
  • 671
  • 3
  • 10