从ng-change功能调用ng-click功能

时间:2017-11-22 12:09:35

标签: javascript angularjs

我是angularjs的新手,如果我错了,请告诉我。

我使用单一选择并想要获取值并基于我想要执行操作的值。例如:如果我将“DELETE”,那么我想将其发送到名称为delete的ng-click功能。以下是我的代码: -

html.jsp

<body ng-app ng-controller="AppCtrl">
<select ng-model="some_action.type"  ng-change="actionchange(some_action.type)" ng-options="type.value as type.displayName for type in types">
</select>
</body>

的script.js

    function AppCtrl($scope) {

        $scope.some_action={
            type: 'Select'
        }

        $scope.types = [
            {value: 'DELETE', displayName: 'Delete'},
            {value: 'SUSPEND', displayName: 'Suspend'}
         ]
    }

$scope.actionchange= function(value) {
     console.log('change action is -'+ value);
     //here I will fetch some ids which will sent to some other's click function
};

所以我单独使用ng-click功能进行这两个动作,并希望从ng-change中使用,这将调用ng-click。

1 个答案:

答案 0 :(得分:0)

    function AppCtrl($scope) {

        $scope.some_action = {
            type: 'Select'
        }

        $scope.types = [{
                value: 'DELETE',
                displayName: 'Delete'
            },
            {
                value: 'SUSPEND',
                displayName: 'Suspend'
            }
        ]
    }

    $scope.actionchange = function(value) {
        console.log('change action is -' + value);
        var fetchIds= [];
        // based on the condition push all ids to fetchIDS

        $scope.method_Delete(fetchIds);
    };

$scope.method_Delete=function(fetchIds){
// do something using fetchIds
}