A
A
Archakov Dennis2016-02-20 22:19:14
JavaScript
Archakov Dennis, 2016-02-20 22:19:14

AngularJS ng-click not working?

If you use $scope.showOrder separately, it works fine. But, if placed in ng-repeat , then there is no reaction.
orders.controller.js

app.controller('MakeOrders', ['$scope', '$compile', function($scope, $compile) {

    $scope.orders = OrdersArr;

    $scope.setOS = function(s){
    	return (s=='123') ? 'iOS' : 'Android';
  }

  $scope.setPayStatus = function(s){
    	return s ? 'оплачено' : 'не оплачено';
  }

  $scope.setId = function(i){
    a = '00000';
    return a.substr(0,5-i.toString().length)+i;
  }

  $scope.showOrder = function(id){
    $('.col-lg-3').css('width','30%');
    var title_id = '00000'.substr(0,5-id.toString().length)+id;
    $('.arrow-back').show();
    $('.panel-header h1').text('Заказ №'+title_id);
    $('.panel-search-box,.panel-content').hide();

      	         var compiledeHTML = $compile("<div order-Info></div>")($scope);
      	         $(".panel-content").after(compiledeHTML);
    }
}]);

app.directive('orderInfo', function() {
  return {
    templateUrl: '/res/admin/order-info.html'
  };
});

index.html
<div ng-controller="MakeOrders" class="panel-order-table">

        <table>
          <tbody>
            <tr ng-click="showOrder(1);"><th>№ ЗАКАЗА</th><th>ДАТА И ВРЕМЯ</th><th>ПЛАТФОРМА</th><th>СУММА</th><th>СТАТУС</th></tr>
            <tr ng-click="showOrder({{order.id}});" class="panel-order-row" ng-repeat="order in orders">
              <td>{{ setId(order.id) }}</td>
              <td>{{order.delivery_time | timestampToDate}}</td>
              <td>{{ setOS(order.client_id) }}</td>
              <td id="order-td-summa">
                <span>{{order.amount}} руб.</span>
                <span class="paid">{{ setPayStatus(order.pay_status) }}</span>
              </td>
              <td id="order-td-status">
                <span class="sprite-icon order-icon-1"></span>
                <span onclick="Orders.StatusBox(true,this);">Принят в обработку</span>
                <div id="dropdown-status" class="dropdown-status">
                  <ul>
                    <li><span>Принят в обработку</span></li>
                    <li><span>Ожидает доставки</span></li>
                    <li><span>Доставлено</span></li>
                    <li><span>Анулировано</span></li>
                  </ul>
                </div>
              </td>
            </tr>
            
          </tbody>
        </table>

      </div>

As you can see, there is one - showOrder(1); and it works. How to fix it so that what's in ng-repeat also works?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Archakov Dennis, 2016-02-20
@archakov06

Found a general solution. StackoverFlow helped.
Instead showOrder({{order.id}});ofshowOrder(order.id);

L
lega, 2016-02-20
@lega

See errors in the console, ng-click does not work with interpolation, you need a js expression:
ng-click="showOrder(order.id);"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question