如何根据函数返回true/false to html并设置禁用值



javaScript函数返回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>

返回视图的结果是错误的,并且没有根据条件改变。

可以有三种情况:

  1. $范围对象如果通过非角度方法触发ISENABLED函数,则不会在视图中应用更改。
  2. 由于某种原因,您的角度消化循环未运行
  3. stx-action-center禁用属性中的解决方法只需调用isEnabled函数,然后从功能(Skip $ scope(返回布尔值

我认为您不是在调用您创建的功能。

请更改

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

javascript

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

更改html

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

这应该解决问题。

最新更新