0

Here is the Scenario

I am getting Data from server in this form

$scope.data=[
{"name":"xyz","status":"pending"},
{"name":"abc","status":"completed"},
{"name":"pqr","status":"completed"}
]

This Data is Seprate GET call for different status

$scope.statusValues=[
{"statusName":"pending","id":"1"},
{"statusName":"completed","id":"2"},
{"statusName":"cancelled","id":"3"},
{"statusName":"custom","id":"4"}
]

In HTML:-

<div ng-repeat="t in data">{{t.name}}</div>

How to Display t.status value inside Select method with more $scope.statusValues

enter image description here

1
  • 1
    Use ng-selected match with ng-model like this................................ <select ng-model="status.statusname"> <option ng-repeat="t in data" title="{{t.title}}" ng-selected="{{t.statusname== status.statusname}}" value="{{t.statusname}}">{{t.statusname}}</option> </select> Commented Dec 5, 2016 at 7:10

2 Answers 2

1

Use key value pair for combine them.

I have created plunker it may helpful.

Plunker

Sign up to request clarification or add additional context in comments.

3 Comments

Thank You fro Replying !! But still by default status value is not getting selected..as it is coming from server..
I have created static replace it with server response.
Exactly.Static data working fine..as soon as I do it with server GET call..it is not selecting default value {{t.status}}
1

You can use ng-options to display all the status and ng-model to bind to your data status

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.data = [{
    "name": "ABC",
    "statusId": "1",
    "status": "completed"
  }, {
    "name": "XYZ",
    "statusId": "2",
    "status": "pending"
  }, {
    "name": "PQR",
    "statusId": "3",
    "status": "assigned"
  }];

  $scope.statusValues = [{
    "statusId": "1",
    "status": "completed"
  }, {
    "statusId": "2",
    "status": "pending"
  }, {
    "statusId": "3",
    "status": "assigned"
  }, {
    "statusId": "4",
    "status": "cancelled"
  }, {
    "statusId": "5",
    "status": "customstatus"
  }, {
    "statusId": "6",
    "status": "customstatus2"
  }];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <div ng-repeat="t in data">
    {{t.name}}
    <select ng-model="t.status" ng-options="s.status as s.status for s in statusValues"></select>
  </div>
</div>

EDIT

Update arrays as discussed in comments

8 Comments

Thank You fro Replying !! But still by default status value is not getting selected..as it is coming from server..
What is the default value ?
If you run the code snippet you can see that each dropdown has the value of the status inside the array data.. Thus the default value IS selected
Yes it will work ..as it is local data..in my case m getting data from server..??can u explain how should i approach.
Use nested then function
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.