复选框angularjs不绑定范围 [英] Checkbox not binding to scope in angularjs

查看:154
本文介绍了复选框angularjs不绑定范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用NG-模型绑定一个复选框范围。该复选框的初始状态对应范围的模型就好了,但是当我检查/取消选中该复选框,该模式不会改变。有些事情要注意的是,模板在运行时使用动态加载NG-包括

I am trying to bind a checkbox to scope using ng-model. The checkbox's initial state corresponds to the scope model just fine, but when I check/uncheck the checkbox, the model does not change. Some things to note is that the template is dynamically loaded at runtime using ng-include

app.controller "OrdersController", ($scope, $http, $location, $state, $stateParams, Order) ->

  $scope.billing_is_shipping = false
  $scope.bind_billing_to_shipping = ->
    console.log $scope.billing_is_shipping


<input type="checkbox" ng-model="billing_is_shipping"/>

当我检查控制台日志假盒子,当我取消勾选,控制台再次登录假的。我也有范围的订单模式,如果我改变复选框的模型中order.billing_is_shipping,它工作正常。

When I check the box the console logs false, when I uncheck the box, the console again logs false. I also have an order model on the scope, and if I change the checkbox's model to be order.billing_is_shipping, it works fine

推荐答案

我挣扎着这个问题了一会儿。什么工作是对输入绑定到对象,而不是原始

I struggled with this problem for a while. What worked was to bind the input to an object instead of a primitive.

<!-- Partial -->
<input type="checkbox" ng-model="someObject.someProperty"> Check Me!

// Controller
$scope.someObject.someProperty = false

这篇关于复选框angularjs不绑定范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆