<i id='TVuRE'><tr id='TVuRE'><dt id='TVuRE'><q id='TVuRE'><span id='TVuRE'><b id='TVuRE'><form id='TVuRE'><ins id='TVuRE'></ins><ul id='TVuRE'></ul><sub id='TVuRE'></sub></form><legend id='TVuRE'></legend><bdo id='TVuRE'><pre id='TVuRE'><center id='TVuRE'></center></pre></bdo></b><th id='TVuRE'></th></span></q></dt></tr></i><div id='TVuRE'><tfoot id='TVuRE'></tfoot><dl id='TVuRE'><fieldset id='TVuRE'></fieldset></dl></div>
      • <bdo id='TVuRE'></bdo><ul id='TVuRE'></ul>
    1. <small id='TVuRE'></small><noframes id='TVuRE'>

      <tfoot id='TVuRE'></tfoot>
      <legend id='TVuRE'><style id='TVuRE'><dir id='TVuRE'><q id='TVuRE'></q></dir></style></legend>

      1. AngularJs:ng-model 未绑定到 ng-checked 输入类型 =“radio",与 ng-r

        AngularJs : ng-model not binding to ng-checked for input type=quot;radioquot;, using with ng-repeat(AngularJs:ng-model 未绑定到 ng-checked 输入类型 =“radio,与 ng-repeat 一起使用)

      2. <tfoot id='zrDjZ'></tfoot>
          <bdo id='zrDjZ'></bdo><ul id='zrDjZ'></ul>
          • <small id='zrDjZ'></small><noframes id='zrDjZ'>

            <i id='zrDjZ'><tr id='zrDjZ'><dt id='zrDjZ'><q id='zrDjZ'><span id='zrDjZ'><b id='zrDjZ'><form id='zrDjZ'><ins id='zrDjZ'></ins><ul id='zrDjZ'></ul><sub id='zrDjZ'></sub></form><legend id='zrDjZ'></legend><bdo id='zrDjZ'><pre id='zrDjZ'><center id='zrDjZ'></center></pre></bdo></b><th id='zrDjZ'></th></span></q></dt></tr></i><div id='zrDjZ'><tfoot id='zrDjZ'></tfoot><dl id='zrDjZ'><fieldset id='zrDjZ'></fieldset></dl></div>
            • <legend id='zrDjZ'><style id='zrDjZ'><dir id='zrDjZ'><q id='zrDjZ'></q></dir></style></legend>
                <tbody id='zrDjZ'></tbody>

                  本文介绍了AngularJs:ng-model 未绑定到 ng-checked 输入类型 =“radio",与 ng-repeat 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用带有表达式跟踪的 ng-repeat 指令来显示单选按钮,当我提交值时附加在模型中并且当我使用模型中的值重新打开页面时,单选按钮不显示检查.

                  我已经实现了平面字符串模型 + 字符串值.但这次我尝试使用对象.

                  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script><div ng-app="app" ng-controller="MyCtrl"><表格名称="myForm"><p>新尝试</p><ul><li ng-repeat="i in peopleNew.person"><标签>{{一世}}

                  JS代码

                   angular.module('app', []).controller('MyCtrl', ($scope) => {$scope.peopleNew ={人: {名称":林戈",id":R",主题":科学"}}$scope.peopleServer= {人:{姓名":林戈"}}});

                  如上所述,我应该在屏幕上有 4 个单选按钮,我可以选择 1 并提交.然后当我再次在我的模型中打开它时,该人具有正确的值,该值已通过 ng-value 保存但仍在 UI 上,我没有看到单选按钮已检查名称 Ringo 应该被检查.型号有:

                   $scope.peopleServer= {人:{姓名:Ringo"}}

                  尝试过的解决方案

                  1. ng-checked 表达式,虽然我读过 ng-model 和 ng-checked不应一起使用,理想情况下应使用模型绑定进行检查.
                  2. 解释我读到,ng-repeat 无法正确渲染,所以我尝试强制重新渲染但没有成功.
                  3. 从模板中移除 ng-checked 仍然无效.
                  4. Track by 适用于 ng-repeat 中的字符串值.在 ng-options 中,它也适用于对象值,但它不是输入元素,而是选择元素

                  有人帮助理解,当您重新加载或您已经拥有模型中的值时,如何选择单选按钮

                   angular.module('app', []).controller('MyCtrl', ($scope) => {$scope.peopleNew ={人: {名称":林戈",id":R",主题":科学"}}//取消注释以进行测试.$scope.peopleServer= {人:{姓名":林戈"}}});

                  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></脚本><div ng-app="app" ng-controller="MyCtrl"><表格名称="myForm"><p>新尝试</p><ul><li ng-repeat="i in peopleNew.person"><标签>{{一世}}

                  自动?我上面的所有尝试都不起作用我错过了什么.

                  解决方案

                  你有一些语法错误,缺少模型值和一些不必要的标记.首先,您可以完全摆脱 ng-checked.如果您正确设置了 ng-modelng-value,这将自动处理.由于您的对象是独一无二的,因此不需要 track by.

                  当使用 AngularJS 指令(例如 ng-value)时,你不需要使用大括号来引用你的模型值.所以 ng-value="{{person}}" 变成了 ng-value="person".

                  您引用了 myObj.person,但似乎没有对应的模型值.下面是您提供的代码和标记的编辑,表明使用对象作为单选按钮的值确实有效.

                  angular.module('app', []).controller('MyCtrl', ($scope) => {$scope.people = [{名称:约翰",编号:J"}, {名称:保罗",编号:P"}, {名称:乔治",编号:G"}, {名称:林戈",编号:R"}];$scope.myObj = {人:$scope.people[1]};});

                  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js"></脚本><div ng-app="app" ng-controller="MyCtrl"><表格名称="myForm"><p>决定</p><ul><li ng-repeat="人中人"><标签>{{ 人名 }}
                  {{ myObj.person }}</div></div>

                  I am trying to use ng-repeat directive with track by expression, to show radio buttons, when I submit the value gets attached in the model and when I reopens the page using the values in model, the radio button does not show checked.

                  I have implemented same with plane string model + string values . But this time am trying with objects.

                  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
                  <div ng-app="app" ng-controller="MyCtrl">
                      <form name="myForm">
                          <p>New TRY</p>
                          <ul>
                              <li ng-repeat="i in peopleNew.person">
                                  <label>
                              {{i}}
                                      <input type="radio" ng-model="peopleServer.person"
                                             name="same" ng-value="i" />
                                  </label>  
                              </li>
                          </ul>
                      </form>
                  <div>
                  

                  JS code

                   angular.module('app', [])
                    .controller('MyCtrl', ($scope) => {
                    $scope.peopleNew ={
                     person: {
                        "name": "Ringo",
                        "id": "R",
                       "subj": "Sci"
                      } 
                    }
                     $scope.peopleServer= {
                     person: {"name":"Ringo"}
                     }
                    });
                  

                  As per above, I should have 4 radio buttons on the screen, I am able to select 1 and submit. And then when I again open it in my model the person have the right value which was saved thorough ng-value but still on UI i don't see the radio button as checked for name Ringo should be checked. Model have:

                   $scope.peopleServer= {
                      person: {name:"Ringo"}
                     }
                  

                  Tried Solutions

                  1. ng-checked expression , although I read that ng-model and ng-checked should not be used together, ideally using model binding it should be chcked.
                  2. explanationI read about ,ng-repeat is not rendering properly so i tried to re render forcefully but did not work.
                  3. Removed ng-checked from the template still did not work.
                  4. Track by works for string values in ng-repeat.In ng-options it worked for object values also, but then its not input element but a select element

                  Someone help understand, when you reload or you already have the value in model,how the radio button be selected

                  	angular.module('app', [])
                    .controller('MyCtrl', ($scope) => {
                    $scope.peopleNew ={
                     person: {
                        "name": "Ringo",
                        "id": "R",
                       "subj": "Sci"
                      } 
                    }
                    //uncomment for testing. 
                     $scope.peopleServer= {
                     person: {"name":"Ringo"}
                     }
                    });

                  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
                  <div ng-app="app" ng-controller="MyCtrl">
                  	<form name="myForm">
                  		<p>New TRY</p>
                  		<ul>
                  			<li ng-repeat="i in peopleNew.person">
                  				<label>
                              {{i}}
                                      <input type="radio" ng-model="peopleServer.person"
                                             name="same" ng-value="i" />
                  				</label>  
                  			</li>
                  		</ul>
                      </form>
                  <div>

                  automatically ? all my tries above are not working am i missing something.

                  解决方案

                  You have some syntax errors, missing model values and some unnecessary markup. First, you can get rid of the ng-checked altogether. That will be handled automatically if you set your ng-model and ng-value properly. Since your objects are unique there's no need for track by.

                  When using AngularJS directives (such as ng-value) you do not need to use braces to reference your model values. So ng-value="{{person}}" becomes ng-value="person".

                  You refer to myObj.person, but there doesn't appear to be a corresponding model value. Below is an edit of the code and markup you have provided showing that it really does work to use an object as the value for your radio buttons.

                  angular.module('app', [])
                    .controller('MyCtrl', ($scope) => {
                      $scope.people = [{
                        name: "John",
                        id: "J"
                      }, {
                        name: "Paul",
                        id: "P"
                      }, {
                        name: "George",
                        id: "G"
                      }, {
                        name: "Ringo",
                        id: "R"
                      }];
                      $scope.myObj = {
                        person: $scope.people[1]
                      };
                    });

                  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js"></script>
                  <div ng-app="app" ng-controller="MyCtrl">
                    <form name="myForm">
                      <p>Decisions</p>
                      <ul>
                        <li ng-repeat="person in people">
                          <label>
                              {{ person.name }}
                              <input type="radio" ng-model="myObj.person"
                                     name="sameName" ng-value="person" />
                          </label>
                        </li>
                      </ul>
                    </form>
                    <div>
                      {{ myObj.person }}
                    </div>
                  </div>

                  这篇关于AngularJs:ng-model 未绑定到 ng-checked 输入类型 =“radio",与 ng-repeat 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  keeping radio buttons checked after form submit(表单提交后保持选中单选按钮)
                  Bootstrap radio button quot;checkedquot; flag(Bootstrap 单选按钮“已选中旗帜)
                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)
                  How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                    <bdo id='iO1sh'></bdo><ul id='iO1sh'></ul>
                      <tbody id='iO1sh'></tbody>
                    <i id='iO1sh'><tr id='iO1sh'><dt id='iO1sh'><q id='iO1sh'><span id='iO1sh'><b id='iO1sh'><form id='iO1sh'><ins id='iO1sh'></ins><ul id='iO1sh'></ul><sub id='iO1sh'></sub></form><legend id='iO1sh'></legend><bdo id='iO1sh'><pre id='iO1sh'><center id='iO1sh'></center></pre></bdo></b><th id='iO1sh'></th></span></q></dt></tr></i><div id='iO1sh'><tfoot id='iO1sh'></tfoot><dl id='iO1sh'><fieldset id='iO1sh'></fieldset></dl></div>

                      <small id='iO1sh'></small><noframes id='iO1sh'>

                        <tfoot id='iO1sh'></tfoot>

                        <legend id='iO1sh'><style id='iO1sh'><dir id='iO1sh'><q id='iO1sh'></q></dir></style></legend>