我是 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。
最佳答案
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
}
关于javascript - 从 ng-change 函数调用 ng-click 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47434375/