0

<select class="form-control" name="suppliername" ng-model="suppliername"  data-ng-change="supplier_data1(suppliername)" required>
 <option value="">Select</option>
 <option ng-repeat="custids in supp_nmArray" value="{{custids.Supplier_Id}}"  >{{custids.name}} 
 </option>                                                       
</select>

<table class="table table-striped" >
    <thead>
    <tr>
        <th>Product Name</th>
        <th>Qty</th>
        <th>Rate</th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="p in products">
        <td>{{ p.Product_Name }}

            <input type="hidden" class="form-control" name="sname" ng-model="sname" required>

        </td>
        <td>
            <input type="text" class="form-control" name="finalqty" ng-model="p.finalqty"  ng-change="change_qty(p.productrate,p.finalqty)"/>
        </td>
        <td>
            <span ng-init="GetProdcutDetails(p.Product_Name,sname,'productrate'+$index)"></span>
            <input type="text" class="form-control" name="purches_rate" ng-model="p.purches_rate" id="productrate{{$index}}">
        </td>
    </tr>
    </tbody>
</table>

var app=angular.module("myapp",['ui.bootstrap']);
app.controller("ctrl",function($scope,$http)
{
 

     $scope.supplier_data1 = function(suppliername)
  {
      $scope.sname=suppliername;
  }
  $scope.GetProdcutDetails = function(Product_Name,sname,productrate)
  {
    $http.post("get_prodcut_rate.php",{'Product_Name':Product_Name,'suppliername':$scope.sname})
        .success(function(data)
        {
          var x = document.getElementById(productrate);
          document.getElementById(productrate).value = data[0].purches_rate;
        });
  }
});

I'am getting product rate value in ng repeat by use of javascript(getElementById).

How to assign the document.getElementById to ng-model in ng-repeat ?

I need to pass the value in another function. kinldy help me

Thanks you in Advance.

konda
  • 185
  • 1
  • 12
  • 2
    There is so much wrong with this approach; don't modify the dom; don't use `ng-init`, don't use `.success`, don't call a function on every iteration of an `ng-repeat`..... – Claies Feb 23 '18 at 11:33
  • ^ bind data to scoped variables; initialise everything in the controller; use `.then` instead – Aleksey Solovey Feb 23 '18 at 11:37
  • essentially, this is the wrong way to do it. calling this `GetProdcutDetails` function inside your `ng-repeat` will cause this function to be called multiple times, and called again multiple times every time your DOM changes. Instead, you should fetch the data beforehand in your controller, so that you minimize the number of times you try to fetch the same data. On top of this, adding the data to `$scope` ensures that you aren't modifying the DOM directly. – Claies Feb 23 '18 at 11:37
  • more code added. On click of supplier that particular product of rate should be needed. but supplier name is an out side of ng repeat. or how to pass the prodcut name to supplier_data1() function. – konda Feb 23 '18 at 11:51
  • @konda you should [never use `id` with AngularJS](https://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background). Everything is bounded to the scope, so just pass your model instead: `GetProdcutDetails(p.Product_Name,sname,p.purches_rate)` and populate it with: `productrate = data[0].purches_rate;`. Or you can pass in $index instead and have `$scope.products[index].purches_rate = data[0].purches_rate;` – Aleksey Solovey Feb 23 '18 at 13:17
  • @AlekseySolovey I used $scope.products[index].purches_rate = data[0].purches_rate; but not fetching value to ng model="p.purches_rate" – konda Feb 23 '18 at 13:42

0 Answers0