即使条件改变,使用ng-禁用按钮仍然是禁用的。

时间:2021-08-06 19:42:24

I have a button:

我有一个按钮:

<button ng-disabled="ctrl.myService.getData().someProperty ? '' : 'disabled'">
  Click me!
</button>

When the application loads someProperty does not exist on ctrl.myService.getData(). So the button is disabled.

当应用程序加载某个属性时,在ctrl.myService.getData()中不存在。所以按钮是禁用的。

But after a few seconds someProperty is set on ctrl.myService.getData() but my button is still disabled .. any idea why its not enabling the button based on the new property?

但是在几秒钟之后,一些属性设置为ctrl.myService.getData(),但是我的按钮仍然是禁用的。你知道为什么它没有启用基于新属性的按钮吗?

2 个解决方案

#1


0  

Also be sure to call $scope.apply() at the end of your methods execution so it can apply the changes necessary

也要确保调用$scope.apply()在方法执行的末尾,这样它就可以应用所需要的更改。

#2


1  

it should be like this:

应该是这样的:

In your controller:

在你的控制器:

     <script>
        app.controller("myCtrl", function($scope) {

           $scope.is_disabled = ctrl.myService.getData().someProperty;
        });
     </script>

In Html:

在Html中:

    <button ng-disabled="is_disabled ? false : true">
      Click me!
    </button>

#1


0  

Also be sure to call $scope.apply() at the end of your methods execution so it can apply the changes necessary

也要确保调用$scope.apply()在方法执行的末尾,这样它就可以应用所需要的更改。

#2


1  

it should be like this:

应该是这样的:

In your controller:

在你的控制器:

     <script>
        app.controller("myCtrl", function($scope) {

           $scope.is_disabled = ctrl.myService.getData().someProperty;
        });
     </script>

In Html:

在Html中:

    <button ng-disabled="is_disabled ? false : true">
      Click me!
    </button>