gpt4 book ai didi

javascript - 在 Controller 中使用 $scope var 使用 ng-disable 禁用 Angular 按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:53 25 4
gpt4 key购买 nike

我的 View 中有两个按钮,我想在加载我的 View 之前禁用摘要按钮。

<div class="btn-group" ng-init="showData = 1">
<button ng-model="showData" type="button" ng-class='{"btn btn-primary": showData == 1, "btn btn-white": showData != 1}' ng-click="showData = 1">Headline</button>
<button ng-model="showData" type="button" ng-class='{"btn btn-primary":showData == 2, "btn btn-white": showData != 2}' ng-click="showData = 2; summaryCall()">Summary</button>
</div>

我有一个变量 $scope.loadMainView = false,当 Web 服务的响应正常时,这个变量变为 true,所以我想禁用我的按钮直到该变量变为真,但我不知道如何实现那个。我正在考虑在 ng-init 上将 $scope 变量初始化为 false,然后将其设置为 ng-disable 或类似的东西,但我不确定,我是 angular 的新手,也许是我的方法根本不正确。

有些帮助会很棒。

最佳答案

使用 ng-disabled

<button ng-disabled="!loadMainView" type="button"></button>

This directive sets the disabled attribute on the element if the expression inside ngDisabled evaluates to truthy.

https://docs.angularjs.org/api/ng/directive/ngDisabled

关于javascript - 在 Controller 中使用 $scope var 使用 ng-disable 禁用 Angular 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37977137/

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