Угловой пропуск метода get, вызывающего веб-сервис

0
    var l = $scope.PendingKOTitems.length,
        k = 0;
    for (k = 0; k < l; k = k + 1) {
        sItemCode = $scope.PendingKOTitems[k]["sItemCode"]
        sOutletCode = $scope.selectedOutlet.sOutletCode;
        sFinal = sOutletCode + "/" + sSubCatgCode

        $http.get(sServiceURL + 'ItemMst/' + sFinal).then(function (resp) {
            $scope.Items = resp.data;
            iindexItem = getIndexOf($scope.Items, sItemCode, "sItemCode");
        }, function (err) {
            console.error('ERR', err);
            // err.status will contain the status code
        })
        sCheckValue = $scope.CheckboxSelection.value;

         $scope.invoice.items.push({
            KOTNo: $scope.KOTNumValue,
            ActiveMode: $scope.lActiveMode,
            SubCatgCode: sSubCatgCode,
            SubCatgDesc: sSubCatgDesc,
            indexSubCatg: iindexSubCatg,
            ItemCode: sItemCode,
            ItemDesc: sItemDesc,
            indexItem: iindexItem,
            Qty: sQty,
            OutletCode: sOutletCode,
            BillType: sBillType,
            MemberCode: sMemberCode,
            RoomNum: sRoomNum,
            BookingCode: dBookingCode,
            TableCode: sTableCode,
            WaiterCode: sWaiterCode,
            UserID: sUserID
        });
    }

Метод get не загорается в цикле for, после выполнения цикла цикла он срабатывает.

Я хочу получить значение "iindexItem" для выбора нагрузки на основе подкатегории товара. Но получите огонь метода после выполнения операции "push". поэтому я не смог получить значение "iindexItem". это моя проблема.

Теги:

1 ответ

0

Я попробовал это, и это, похоже, отлично работает для меня -

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="/angular.js"></script>
</head>
<body ng-app="app">
 <div ng-controller="ctrl">

 <h1>This is a Heading</h1>
 <p>This is a paragraph.</p>
</div>
<script type="text/javascript">
  var angularapp = angular.module("app",[]);

  angularapp.controller('ctrl', ['$scope', '$window', '$http', '$filter', '$timeout', MyCtrl]);

  function MyCtrl($scope, $window, $http, $filter, $timeout){

  for(var i=0; i<3; i++){
   $http.get("http://httpbin.org/get").then(function (resp) {
     debugger;
     $scope.Items = resp.data; // here I set my breakpoint
     console.log(i);
     console.log(resp.data);
 }, function (err) {

    console.error('ERR', err);
    // err.status will contain the status code
  });
 }

}
</script>
</body>
</html>     

Отладчик попадает на каждую итерацию в цикле for.

  • 0
    отладчик нажал после завершения цикла for. Я отправил всю свою петлю в моем вопросе.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню