【问题标题】:binding radio buttons to ng-model with angularjs使用 angularjs 将单选按钮绑定到 ng-model
【发布时间】:2015-10-13 21:09:58
【问题描述】:

所以这是我的 html 代码的相关部分。我尝试将“formFriendsAll”范围绑定到 ng-model。

<form ng-submit="submitForm()" >
   <div class="col-sm-3">
    <div class="form-group"> 
     <label>Which Persons to show?</label>
      <div class="radio">
        <label>
          <input type="radio" name="FriendsAll" ng-model="formFriendsAll" value="Friends" >
          Friends
        </label>
        </div>
         <div class="radio">
          <label>
           <input type="radio" name="FriendsAll" ng-model="formFriendsAll" value="Alle">
           All
          </label>
          </div>
          <div>currently selected: {{formFriendsAll}}</div>
         </div>           
        </div><td><input type="submit" class="btn btn-primary" value="Los!"/></td> </form>    

这是相关的js代码:

 var challenge =  angular.module('challengeApp', []) 
    challenge.controller('challengeController', function($scope) {   

      $scope.submitForm = function () {
      alert($scope.formFriendsAll);   
};  

    $scope.formFriendsAll = 'Friends';

});

当我点击提交按钮时,我使用警报来测试值的变化,但我尝试了各种方法,如 ng-changed、ng-click、ng-value。但没有什么能帮助我解决我的警报和“当前选择”停留在“朋友”上的问题

有什么建议吗?

【问题讨论】:

    标签: javascript angularjs html radio-button angularjs-ng-model


    【解决方案1】:

    好的,伙计们。似乎我在脑海中用于设计单选按钮的 AdminLTE.css 以某种方式阻止了角度

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 2017-08-16
      • 2014-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多