Home  >  Article  >  Web Front-end  >  How to get radio buttons in angularjs

How to get radio buttons in angularjs

php中世界最好的语言
php中世界最好的语言Original
2018-04-12 15:35:492019browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn