Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use embargo Date/time in php 29 38
jquery auto complete 11 17
Scroll 5 news at a time. 4 27
Add email address from a web page to outlook 2010 contacts ? 8 27
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…
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…

773 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