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

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

          <bdo id='rwhov'></bdo><ul id='rwhov'></ul>
      1. AngularJS:初始复选框值不在模型中

        AngularJS: Initial checkbox value not in model(AngularJS:初始复选框值不在模型中)
        • <small id='1P1fp'></small><noframes id='1P1fp'>

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

            <bdo id='1P1fp'></bdo><ul id='1P1fp'></ul>

            <tfoot id='1P1fp'></tfoot>

                <tbody id='1P1fp'></tbody>

                  本文介绍了AngularJS:初始复选框值不在模型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有这样复选框的表单:

                  I have got a form with a checkbox like this:

                  <input type="checkbox" name="publish" id="publish" ng-model="data.publish" ng-true-value="Yes" ng-false-value="No"/>
                  

                  现在我想将其初始值 'No'(因为它未选中)绑定到模型,而无需单击复选框.除了在控制器中手动设置模型值或使用 ngInit 之外,还有其他方法吗?

                  Now I would like to have its initial value 'No' (becuase it is unchecked) bound to the model without having to click on the checkbox. Is there a way besides setting the model value manually in the controller or using ngInit?

                  我的脚本应该适用于不同的形式,因此手动设置模型变量是不可行的.而且 ngInit 方法看起来相当不优雅.

                  My script should work with different forms so manually setting model variables is no option. And the ngInit method seems rather inelegant.

                  推荐答案

                  可能是这样的指令:

                  <input type="checkbox" ng-model="..." init-cb ... />
                  

                  下面的代码应该做到这一点:

                  The following code should do it:

                  m.directive("initCb", function() {
                      return {
                          require: ["ngModel"],
                          scope: false,
                          link: function(scope, element, attrs, controllers) {
                              var ngModel = controllers[0],
                              if( element[0].checked ) {
                                  ngModel.$setViewValue(attrs.ngTrueValue || true);
                              }
                              else {
                                  ngModel.$setViewValue(attrs.ngFalseValue || false);
                              }
                          }
                      };
                  });
                  

                  这篇关于AngularJS:初始复选框值不在模型中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                  How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                  How to use coffeescript in developing web-sites?(如何在开发网站时使用coffeescript?)

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

                • <tfoot id='bXqAU'></tfoot>
                    <tbody id='bXqAU'></tbody>
                    <legend id='bXqAU'><style id='bXqAU'><dir id='bXqAU'><q id='bXqAU'></q></dir></style></legend>

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