gpt4 book ai didi

javascript - Angular ng-disable 未按预期工作

转载 作者:行者123 更新时间:2023-11-28 13:23:16 25 4
gpt4 key购买 nike

当指令发出就绪状态时,我尝试禁用 Controller 中的按钮。

我将 bool 值传递给 ng-disabled:

<button ng-disabled="{{pointsClaimed}}" ng-click="playVideo()">{{buttonText}}</button>

我的 Controller :

    $scope.buttonText = 'Watch Video to Claim Points';
$scope.pointsClaimed = false;

$scope.$on('pointsClaimed', function(){
$scope.buttonText = 'Points Claimed!';
$scope.pointsClaimed = true;
});

我可以看到按钮从 false 变为 true:

enter image description here

enter image description here

但实际按钮并未被禁用。

如果我硬编码 true 或 false,它会按预期工作。如果 HTML 中的值按预期发生变化,为什么按钮没有被禁用?

最佳答案

认为您不需要大括号。尝试一下..

<button ng-disabled="pointsClaimed" ng-click="playVideo()">{{buttonText}}</button>

Demo

docs 中也是一个很好的演示.

关于javascript - Angular ng-disable 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31395320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com