Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
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 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)

747 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

12 Experts available now in Live!

Get 1:1 Help Now