0

I have the following expression wrapped into a scope function to disable the add button in view using angularJS ng-disabled directive :

$scope.disableAddButton = function() {
    return (!(currentObjCopy.name || currentObjCopy.name.trim() || currentObjCopy.numAttachments) &&
            (mac.input != 'static' || currentObjCopy.name.trim() == '')) ||
            !(selectedRow && currentObjCopy) ||
            ((mac.input != 'random' && !staticMacTemp.length) && !currentObjCopy.startMac));
}

Is there any other alternatives to optimize this expression to pass into ng-disable as follows :

<button type="button" class="px-Button px-Block-Element" ng-click='addLocal()'
                            ng-disabled="!disableAddButton()">Add</button>

When passing the expressions directly to the directive working fine But passing as a function which results not disabling the button even the expressions are false.

Kindly ignore the Js variables/objects since they could be undefined or null or empty

georgeawg
  • 48,608
  • 13
  • 72
  • 95
S.K. Venkat
  • 1,749
  • 2
  • 23
  • 35
  • are you sure you didn't forget to use `$scope` before `currentObjCopy` and the others ? – Walfrat Aug 10 '16 at 14:35
  • *@Walfrat* Thanks for the clue. Sorry, I didn't invoke those variables using $scope. I have declared that one in a controller and the function disableAddButton() also resided in same place. Also I have tried that now and observed the same result still. – S.K. Venkat Aug 10 '16 at 14:39

0 Answers0