在angular中使用select来传递多个参数

在angular中使用select来传递多个参数

问题描述:

在Angular Js中有没有一种方法可以像链接列表一样使用select元素?在angular中使用select来传递多个参数

例如,如果我有一些像这样的链接:

<a ng-click="ctrl.change('argument1','argument2')">One</a> 
<a ng-click="ctrl.change('argument3','argument4')">Two</a> 
... 

有没有一种方法可以让我做同样的事情与选择的元素?

<select> 
    <option value="argument1,argument2">One</option> 
    <option value="argument3,argument4">Two</option> 
    ... 
</select> 
+0

'ng-change'怎么样? – Rayon

+0

我想过,但我不知道如何用多个参数来做到这一点。有什么想法吗? –

+0

像'

你是不是说这个?使用控制器的值,而不是范围值,如果u希望

<select ng-options="['a,b','c,d']" ng-model="selected" ng-change="ctrl.change(selected)">

您可以通过ng-change,下面的代码,希望可以帮助您通过变量和模型,

模板

<div ng-controller="myCtrl"> 
     <select ng-model="item" ng-options="i.name for i in items" ng-change="changed('hello','world',item)"> 
      <option value="">choose items</option> 
     </select> 
</div> 

controll呃

function myCtrl($scope) { 

    $scope.items = [{ 

      "name": "first", 
      "type" : "type1" 

    }, { 

      "name": "second", 
      "type" : "type2" 

    }, { 

      "name": "third", 
      "type" : "type3" 

    }]; 


    $scope.changed = function (hello,world,item) { 
     alert(hello); // argument1 
     alert(world); //argument2 
     alert(item.type); //model argument based on the selection 
    } 

}