Archakov Dennis2016-02-20 22:19:14
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.

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){
    var title_id = '00000'.substr(0,5-id.toString().length)+id;
    $('.panel-header h1').text('Заказ №'+title_id);

      	         var compiledeHTML = $compile("<div order-Info></div>")($scope);

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

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

            <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 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">
                    <li><span>Принят в обработку</span></li>
                    <li><span>Ожидает доставки</span></li>


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)
Archakov Dennis, 2016-02-20

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

lega, 2016-02-20

See errors in the console, ng-click does not work with interpolation, you need a js expression:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question