ng-change和ng-click在切换按钮bootstrap-toggle中不起作用

时间:2016-08-10 06:06:01

标签: javascript jquery angularjs

点击或ng-change无法切换按钮。我在这里使用toggle-bootstrap包

<input checked 
       data-toggle="toggle" 
       data-size="small" 
       type="checkbox"
       data-on="16x9" 
       data-off="4x3"
       ng-true-value="'16x9'"
       ng-false-value="'4x3'"
       ng-model="slideMode" 
       ng-change="setSlideMode()">

角度代码

 $scope.slideMode = '16x9';
 $scope.setSlideMode = function(){
        console.log($scope.slideMode);
 };

2 个答案:

答案 0 :(得分:2)

设置范围值语法是错误的。

$scope.slideMode = '16x9';

答案 1 :(得分:2)

您应该将ngModel指令添加到输入组件:

    "amqplib": "^0.4.2",
    "async": "^2.0.0-rc.6",
    "aws-sdk": "^2.4.4",
    "dogapi": "^2.3.0",
    "elasticsearch": "^11.0.1",
    "elasticsearch-streams": "0.0.9",
    "gcloud": "^0.37.0",
    "googleapis": "^9.0.0",
    "moment": "^2.14.1",
    "node-uuid": "^1.4.7",
    "util": "^0.10.3"

将check变量添加到控制器

 <input
    ng-model="check"
   data-toggle="toggle" 
   type="checkbox" 
   ng-change="test()">

这里是plunker示例:https://plnkr.co/edit/r21V3E4upBNxIm16zakj?p=preview