Home >Web Front-end >JS Tutorial >How to get radio buttons in angularjs
This time I will bring you the method of getting the radio button in angularjs, and the attention to getting the radio button in angularjs What are the matters ? Below are actual cases, let’s take a look at them.
In the Html page, there are three radio buttons. The second "Important" option is selected by default. Set ng-checked="true" to select this option by default. However, when submitting the form, it prompts $scope. The level is undefinestate. Why is it undefine when it is clearly selected by default?
So, I tested it first: write the following code on the Html page:
<span style="font-size:18px;"><p ng-controller="testCtrl"> <p > <label > <input type="radio" value="Normal" ng-model="level" name="level" >一般 </label> <label > <input type="radio" value="Important" ng-model="level" name="level" ng-checked="true" >重要 </label> <label > <input type="radio" value="Urgent" ng-model="level" name="level" >紧急 </label> </p> <p> {{ level }}</p> //显示单选按钮选中的value </p></span>
The first time the page is loaded, although the "Important" radio button is selected by default, the page does not display the value corresponding to the "Important" radio button,
Click the "Emergency" button, the value of the "Emergency" button will be displayed below,
It turns out that when the page is loaded, $scope.level is not assigned a value and has no initial value. Even if ng-checked="true", the default selected value is not displayed! Need to be set in js: $scope.level= "Important"; At this time, refresh the page and the value of the selected button will be displayed by default
I believe you have mastered it after reading the case in this article Method, for more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
readlineHow to read line by line Get and write the content
vue determines whether the input content has spaces
The above is the detailed content of How to get radio buttons in angularjs. For more information, please follow other related articles on the PHP Chinese website!