<bdo id='a9vhz'></bdo><ul id='a9vhz'></ul>
  • <legend id='a9vhz'><style id='a9vhz'><dir id='a9vhz'><q id='a9vhz'></q></dir></style></legend>
  • <small id='a9vhz'></small><noframes id='a9vhz'>

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

        复选框检查了 Angular2 的布尔值是否为真

        时间:2023-09-04

      1. <small id='uFU0R'></small><noframes id='uFU0R'>

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

              <tbody id='uFU0R'></tbody>

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

                  本文介绍了复选框检查了 Angular2 的布尔值是否为真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道如何使用 Angular2 使复选框选中值是否为真,如果值为假则取消选中.

                  I would like to know how to make a checkbox checked if the value is true, and unchecked if false with Angular2.

                  Adult <input type="checkbox" value="{{person.is_adult}}">
                  

                  {{person.is_adult}} 是一个 boolean

                  {{person.is_adult}} is a boolean

                  有人可以提出任何建议吗?谢谢

                  Can someone please suggest anything? Thanks

                  推荐答案

                  {{}} 做字符串插值和字符串化truefalseAngular 默认使用属性绑定,我假设属性需要布尔值而不是字符串:

                  {{}} does string interpolation and stringifies true and false and Angular by default uses property binding and I assume the property expects boolean values not strings:

                  <input type="checkbox" [checked]="person.is_adult">
                  

                  这可能也有效

                  <input type="checkbox" attr.checked="{{person.is_adult}}">
                  

                  因为使用属性绑定,浏览器可能会在将属性(只能是字符串)读取到其属性时将其转换为布尔值.

                  because with attribute binding the browser might translate it from the attribute (which can only be strings) to boolean when reading it into its property.

                  也是checked而不是value

                  你也可以使用ngModel

                  <input type="checkbox" [ngModel]"person.is_adult" name="isAdult">
                  <input type="checkbox" [(ngModel)]"person.is_adult" name="isAdult">
                  

                  用于单向或双向绑定.
                  如果您使用 ngModel,请确保您已导入 FormsModule.

                  for one-way or two-way binding.
                  Ensure your have the FormsModule imported if you use ngModel.

                  这篇关于复选框检查了 Angular2 的布尔值是否为真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么 (null == false) 和 (null == true) 都返回 false? 下一篇:(真 + 假) >2 + 真;为什么这会返回假?

                  相关文章

                • <tfoot id='he0N6'></tfoot>
                    <bdo id='he0N6'></bdo><ul id='he0N6'></ul>
                    <legend id='he0N6'><style id='he0N6'><dir id='he0N6'><q id='he0N6'></q></dir></style></legend>

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

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