0

My data is coming from database and want to make dropdown selected in angular.

Payment status coming from database and field name is payment_status For Ex- if payment status is PENDING then selected Payment Pending otherwise Payment Received

Here is my code.

<div ng-repeat="product in data" class="order-received animated fadein delay-1">
<div class="order-header">
  <img class="avatar rectangle" src="img/user4.jpg" alt="">
  <div class="order-author">
    <span style="color:#cc0066;">{{product.GLname}} - {{product.mobno}}</span>
    <span class="small">Item - {{product.item_name}} ({{product.item_code}})</span>
    <span class="small">Qty - {{product.pqty}} Amt - Rs. {{product.rate}}</span>
    <select class="browser-default" style="margin-bottom:8px;" ng-model="paymentOption">
      <option value="RECEIVED">Payment Received</option>
      <option value="PENDING">Payment Pending</option>
    </select>
    <select class="browser-default" ng-model="orderOption">
      <option value="NEW">New Order</option>
      <option value="PROCESS">In Progress</option>
      <option value="SENT">Sent</option>
      <option value="DELIVERED">Delivered</option>
      <option value="CANCELLED">Cancelled</option>
    </select>               
  </div>
</div>            

Please help!!!

2
  • 1
    What do you mean by make dropdown selected in Angular? You want to have a default selected option in your select element? Commented Jan 27, 2017 at 7:16
  • On what rules are you selecting a default? Commented Jan 27, 2017 at 7:20

3 Answers 3

2

You have to change the model value to display something in the select

Since you said that you have field payment_status, you can use

ng-model="product.payment_status"

Here is the html,

<div ng-repeat="product in data" class="order-received animated fadein delay-1">
<div class="order-header">
  <img class="avatar rectangle" src="img/user4.jpg" alt="">
  <div class="order-author">
    <span style="color:#cc0066;">{{product.GLname}} - {{product.mobno}}</span>
    <span class="small">Item - {{product.item_name}} ({{product.item_code}})</span>
    <span class="small">Qty - {{product.pqty}} Amt - Rs. {{product.rate}}</span>
    <select class="browser-default" style="margin-bottom:8px;" ng-model="product.payment_status">
      <option value="RECEIVED">Payment Received</option>
      <option value="PENDING">Payment Pending</option>
    </select>
    <select class="browser-default" ng-model="orderOption">
      <option value="NEW">New Order</option>
      <option value="PROCESS">In Progress</option>
      <option value="SENT">Sent</option>
      <option value="DELIVERED">Delivered</option>
      <option value="CANCELLED">Cancelled</option>
    </select>               
  </div>
</div>    
Sign up to request clarification or add additional context in comments.

2 Comments

@Arvind, check my answer
@ArvindJaiswal, GLad to help you. you can accept my answer if you find it useful.
0

You just define paymentOption value in controller :

as like in controller

$scope.paymentOption = success.payment_status // value fetch from database

Comments

-1

You should set "paymentOption" to one of the values in the Select in the controller.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.