简体   繁体   中英

How do I return true/false based on the function to HTML and set the disabled value?

Javascript function to return true/false.

$scope.createDisabled = false;      
function isEnabled() {
                    if ($scope.node.activationStatus == "Y") {
                        $scope.createDisabled = true;
                    } 
                    else {
                        $scope.createDisabled = false;
                    }
                }

HTML

<stx-action-create disabled="createDisabled"></stx-action-create>

The result that was returned to the view was false and it did not change according to the condition.

There can be three cases:

  1. $scope object does not apply changes in view if you isEnabled function being trigger by a non angular method.
  2. For some reason your angular digest cycle not being run
  3. Workaround in stx-action-center disabled attribute just call the isEnabled function and return the Boolean from the function(skip $scope)

I think you are not invoking the function you created.

Please make changes

to your html as shown below. 
<stx-action-create disabled="isEnabled()"></stx-action-create>

Changes in JavaScript

$scope.createDisabled = false; // Not sure if this is necessary
$scope.isEnabled = function () { // Make the method available on $scope
    return ($scope.node.activationStatus == "Y");
}

Changes in HTML

<stx-action-create disabled="isEnabled()"></stx-action-create> 

This should solve the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM