o1n3n21
o1n3n21

Reputation: 364

AngularJS: Multiple list select option from same data

Let's say I have two lists, that both depend on the same JSON data. For example:

myApp.controller('MainCtrl', function($scope) {

  $scope.print = {};

  $scope.styles = [
    { style: 0, full:10, cut: '321'  },
    { style: 1, full:11, cut: '432' },
    { style: 2, full:12, cut: '543' }
  ];

And then the two lists:

<li class="listOne" ng-repeat="style in styles" item="style" ng-click="print.styleValue = style.full">

<li class="listTwo" ng-repeat="style in styles" item="style" ng-click="print.styleValue = style.full">

And I would like to print the selected value of each list, without the second selection (which comes after the first), changing the selected value. This being {{ selected "cut" from ListOne}} {{ Selected "cut" of Value from ListTwo }}.

{{ print.styleValue }} {{ print.styleValue }} 

Possibly this needs two controllers, or another $scope, for example $scope.styles2, and duplicate the JSON data. I would like to avoid duplicating the JSON data though, so if there's a way that would be amazing! Thanks.

Upvotes: 0

Views: 47

Answers (1)

shaunhusain
shaunhusain

Reputation: 19748

The ng click variable you assign to for each just needs to be unique change one to print.styleValue2

Upvotes: 1

Related Questions