Solved

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

Posted on 2014-01-08
1
351 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now