0

In Angular Js is there a way to use a select element the same way you can with a list of links?

For example if I have some links like this:

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

Is there a way I can do the same thing with a select element?

<select>
    <option value="argument1,argument2">One</option>
    <option value="argument3,argument4">Two</option>
    ...
</select>
5
  • How about ng-change ? Commented Oct 15, 2015 at 8:58
  • I thought about that, but I can't figure out how to do it with multiple arguments. Any thoughts? Commented Oct 15, 2015 at 9:01
  • Like <select ng-change='ctrl.change('argument1','argument2')'> Commented Oct 15, 2015 at 9:02
  • How would that work with different arguments from each select option? Commented Oct 15, 2015 at 9:05
  • 1
    I think you have an array of objects, just pass object values as an argument. Commented Oct 15, 2015 at 9:06

2 Answers 2

1

you can pass the variables and model through ng-change , hope below code helps you,

template

<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>

controller

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
    }

}
Sign up to request clarification or add additional context in comments.

Comments

0

do u mean this? use controller value instead of scope value if u wish

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.