Solved

angularjs two comboboxes bound to different models how can I get models that are selected

Posted on 2014-01-08
1
362 Views
Last Modified: 2014-01-20
I want to have two combo boxes built based on an array of objects in angular.  One is bound to positions, the other is bound to transactions.  I want to select one row on each then click a button and pass each into a function.

Q: How can I pass the selected position and the selected transaction into a function when a user clicks a button?

<select size="10">
<option ng-repeat="transaction in transactions" value="{{transaction.id}}">{{transaction.symbol}}</option>
</select>  

<select size="10">
<option ng-repeat="position in positions" value="{{position.id}}">{{position.title}}</option>
</select>

<button ng-click="?????????">

Open in new window

0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39766471
Check this : http://jsfiddle.net/rB9Qn/

<form ng-app ng-controller="myCtrl">
    <select size="10" ng-model="currTansaction" ng-options="transaction.symbol for transaction in transactions"></select>
    <select size="10" ng-model="currPosition" ng-options="position.title for position in positions"></select>
    <button ng-click="readTransactionANDPosition()">CLICK</button>
</form>

Open in new window


function myCtrl($scope) {

    $scope.transactions = [{id:1,symbol:"$"},{id:2,symbol:"€"}];
    $scope.currTansaction = $scope.transactions[0];

    $scope.positions = [{id:1,title:"services"},{id:1,title:"goods"}];
    $scope.currPosition = $scope.positions[0];

    $scope.readTransactionANDPosition = function() {
        var transaction = $scope.currTansaction.symbol;
        var position = $scope.currPosition.title;
        alert("Transaction is: " + transaction + "\nPosition is: " + position);
    }
}

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question