javascript - 选择切换按钮取消选择时,第一次不会触发 Ionic ng-change

标签 javascript jquery angularjs ionic-framework

我试图获取切换的值,但在检查它工作正常后第一次点击未选中的切换按钮时它不起作用。

<ul class="list  has-header">
  <li class="item item-toggle" ng-repeat="ingr in ingredients|filter:searching">
    {{ingr.INGREDIENTNAME}}
    <label class="toggle toggle-energized" >
      <input type="checkbox" ng-model="ingr.INGREDIENTSTATUS" ng-change='changeingrStatus(ingr.INGREDIENTCODE,ingr.INGREDIENTSTATUS)' ng-checked="{{ingr.INGREDIENTSTATUS==1?true:false}}">
      <div class="track">
        <div class="handle"></div>
      </div>
    </label>
  </li>
</ul>

Controller .js

$scope.changeingrStatus = function(code, status) {
  console.log(status);
}

最佳答案

您不能将 ng-model 属性与 ng-checked 一起使用。我建议仅使用 ng-model

阅读ngChecked详情页面:

Note that this directive should not be used together with ngModel, as this can lead to unexpected behavior.

关于javascript - 选择切换按钮取消选择时,第一次不会触发 Ionic ng-change,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41937403/

相关文章:

javascript - 对 javascript 函数和 php 查询使用相同的计数器

javascript - Outlook Office Addin 未在 div 中显示 HTML 页面

angularjs - Controller :ctrlfmt Badly formed controller string '' . 必须匹配 `__name__ as __id__` 或 `__name__`

javascript - 循环中异步函数的延迟返回

javascript - 在多个 html 文件上运行 javascript

javascript - 实时绑定(bind)是什么意思?

javascript - 匹配 JSON 对象中的键/值

jquery - 单击时移动图像(有点类似于谷歌地图)

php - 基于 Jquery Ajax 的搜索

javascript - Angular Material 和 meteor 的控制台错误