gpt4 book ai didi

javascript - 如果值大于 1,Angularjs ng-disabled 将被禁用

转载 作者:行者123 更新时间:2023-11-30 17:09:42 24 4
gpt4 key购买 nike

我有一些来自 json 的值。如果我的值为 0,则点击工作正常。但如果来自 json 的值大于 0,则该按钮将被禁用并且最初无法正常工作。我正在尝试使用此代码来做喜欢和不喜欢的选项。这样用户就可以选择“喜欢按钮”一次或“不喜欢按钮”一次。对此有什么解决方案吗?

     //html
<button class="label" ng-disabled="tvshow.episode.ratings.loved" ng-init="tvshow.episode.ratings.loved" ng-click="likeme(tvshow.episode)" >
<i class="icon-thumbs-up"></i>
{{tvshow.episode.ratings.loved}}</button>

<button class="label" ng-disabled="tvshow.episode.ratings.hated" ng-init="tvshow.episode.ratings.hated" ng-click="dislike(tvshow.episode)" >
<i class="icon-thumbs-down"></i>
{{tvshow.episode.ratings.hated}}</button>

//added click event for like and dislike buttons in js
$scope.likeme = function(episod){
episod.ratings.loved = parseInt(episod.ratings.loved) + 1;
if (parseInt(episod.ratings.hated) > 0)
episod.ratings.hated = parseInt(episod.ratings.hated) - 1;
episod.liked = true;
episod.disliked = false;
};

最佳答案

您已经拥有所需的所有 Controller 功能。

只需将您的标记更改为:

<button class="label" ng-disabled="tvshow.episode.liked" ng-click="likeme(tvshow.episode)">
<i class="icon-thumbs-up"></i>
{{tvshow.episode.ratings.loved}}
</button>
<button class="label" ng-disabled="tvshow.episode.disliked" ng-click="dislike(tvshow.episode)">
<i class="icon-thumbs-down"></i>
{{tvshow.episode.ratings.hated}}
</button>

请注意,我删除了不执行任何操作的 ng-init,如果每个按钮已被单击,则将其禁用。

关于javascript - 如果值大于 1,Angularjs ng-disabled 将被禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27285595/

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