【问题标题】:$watch on checkbox not working$watch 复选框不起作用
【发布时间】:2016-10-12 18:04:46
【问题描述】:

我正在使用angular-bootstrap-checkbox,如下所示:

HTML

<checkbox class="checkbox" ng-model="manualPosition"></checkbox>

我想观察复选框值的变化。

JS

$scope.$watch('manualPosition', function(manualPosition) {
    console.log('here');
});

这对我不起作用。

【问题讨论】:

    标签: angularjs checkbox watch


    【解决方案1】:

    你必须为 $scope 变量添加一个监视

    $scope.$watch('manualPosition', function (checkboxVal) {
        console.log(checkboxVal);
    });
    

    而你的html应该是这样的,

    <input type="checkbox"  ng-model="manualPosition"> CLICK</input>
    

    DEMO

    【讨论】:

    • 感谢您的快速回复。我很抱歉错字。我也做过同样的事情。但不适合我。
    • 再次感谢。这种方式对我有用。因为在我的项目中我们已经在使用angular-bootstrap-checkbox,所以我希望$watch 能够解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多