简体   繁体   English

角度,需要检查1个单选按钮才能执行操作

[英]angular, require 1 radio button to be checked to perform action

I have some radio buttons set on items (none are checked to begin with) that I have associated a button press. 我在与按钮按下相关的项目上设置了一些单选按钮(一开始都没有选中)。 I would like this action NOT to do anything if no radios are checked off (because it requires information of one of the radios). 如果没有选中任何无线电,我希望此操作不做任何事情(因为它需要其中一个无线电的信息)。

So I just have this button: 所以我只有这个按钮:

<button class="openButton" ng-click="showSubLevel = ! showSubLevel">Add Sub Level</button>

Which opens another div using 这将使用打开另一个div

<div class="addSubLevel" ng-show="showSubLevel"> 

However I would like the button to do nothing (or alert the user) that they have to select a radio to open the .addSubLevel div. 但是,我希望该按钮不执行任何操作(或提醒用户),他们必须选择一个无线电才能打开.addSubLevel div。

The radios just look this like this : 收音机看起来像这样:

<input type="radio" name="instructionLevelChecker">

As I'm not sure what I have to add to them to make this work. 由于我不确定要添加什么内容才能使其正常工作。 Appreciate any input, as I am still new to angular. 感谢任何输入,因为我仍然对角度不熟悉。 Thanks! 谢谢!

You can add ng-disabled="none-checked" to button: 您可以将ng-disabled =“ none-checked”添加到按钮:

<button class="openButton" ng-click="showSubLevel = ! showSubLevel" ng-disabled="none-checked">Add Sub Level</button>

..and set the none-checked variable to false when the user check the first radio button: ..并在用户检查第一个单选按钮时将none-checked变量设置为false:

<input type="radio" name="instructionLevelChecker" ng-click="changeState()>

Javascript in your controller: 控制器中的Javascript:

$scope.none-checked = true;
$scope.changeState = function () {
   $scope.none-checked = false;
}

Hope this help you. 希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM