AngularJS - Trigger when radio button is selected

前端 未结 7 1618
有刺的猬
有刺的猬 2020-11-30 21:13

I searched and tried many ng-xxxx kind of options but couldn\'t find the one.. I just want to call some function in the controller when radio button is selected.

So

相关标签:
7条回答
  • 2020-11-30 21:48

    Should use ngChange instead of ngClick if trigger source is not from click.

    Is the below what you want ? what exactly doesn't work in your case ?

    var myApp = angular.module('myApp', []);
    
    function MyCtrl($scope) {
        $scope.value = "none" ;
        $scope.isChecked = false;
        $scope.checkStuff = function () {
            $scope.isChecked = !$scope.isChecked;
        }
    }
    
    
    <div ng-controller="MyCtrl">
        <input type="radio" ng-model="value" value="one" ng-change="checkStuff()" />
        <span> {{value}} isCheck:{{isChecked}} </span>
    </div>   
    
    0 讨论(0)
提交回复
热议问题