【问题标题】:Change input -> change checkbox model without click更改输入 -> 无需单击即可更改复选框模型
【发布时间】:2016-01-20 09:17:22
【问题描述】:

如果您更新文本输入模型“sg.Value”,应选中复选框,但未设置模型“sg.AnswerId”。

如何获得:

更改文本输入 -> 设置复选框模型?

<label>
  <input type="checkbox"
         ng-model="sg.AnswerId"
         ng-true-value="'{{answer.Id}}'"
         ng-checked="sg.Value != undefined"
         >
  <input type="text"
         placeholder="Your text"
         ng-model="sg.Value"
         >
</label>

当我输入输入时,复选框必须被选中并更新模型。

【问题讨论】:

    标签: javascript angularjs checkbox


    【解决方案1】:

    我的解决方案是plunkr

    输入变化的监听器:

    function trackInput(){
      if(sg.Value !== '' && sg.Value !== undefined) {
        sg.AnswerId = sg.answer.Id;
      } else {
        sg.AnswerId = false;
      }
    };
    

    也许有人有更好的解决方案?请分享。

    【讨论】:

      猜你喜欢
      • 2022-07-06
      • 2020-01-20
      • 2019-12-25
      • 1970-01-01
      • 2020-11-05
      • 2013-07-18
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      相关资源
      最近更新 更多