Solved

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

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

830 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