简体   繁体   English

在HTML中呈现角度错误

[英]Error on rendering angular in html

I have an Angular project where in one view you have a list of orders, of those orders you will see only the title, once you click on that title, you should be redirected by the list.id to a new view where you would see the full content of the order. 我有一个Angular项目,在一个视图中,您有一个订单列表,在这些订单中,您只会看到标题,一旦单击该标题,您应该通过list.id重定向到一个新视图,在该视图中您将看到订单的全部内容。

This is the html where you should see the title of that order 这是html,您应该在其中看到该订单的标题

<a ng-href="#/orders/{{list.id}}" ng-repeat="list in detalleOrden">
   <h5>Orden {{list.id}}</h5>
   <p>{{list.unidadEjec}}</p>       
</a>

and here the HTML where you should see the full content of the order. 此处是HTML,您应该在其中查看订单的全部内容。 Watch the HTML above ng-href="#/orders/{{list.id}}" 观看ng-href="#/orders/{{list.id}}"上方的HTML ng-href="#/orders/{{list.id}}"

<table class="table">
    <tbody>
        <tr>
            <th>Supervisor</th>
            <td ng-bind="list.supervisor"></td>
        </tr>
        <tr>
            <th>Responsable:</th>
            <td>{{list.responsable}}</td>
        </tr>
        <tr>
            <th>Solicitante:</th>
            <td>{{list.solicitante}}</td>
        </tr>
        <tr>
            <th>Unidad ejecutora:</th>
            <td>{{list.unidadEjec}}</td>
        </tr>
    </tbody>
</table>

in that I am not using any ng-repeat, should I ? 因为我没有使用任何ng-repeat,应该吗?

here the code: 这里的代码:

$routeProvider
  .when('/orders', {
    templateUrl: 'views/main.html',
    controller: 'OrderDetailsCtrl',
    resolve: {
      orders: function(Order) {
        return Order.list();
      }
    }
  })
  .when('/orders/:id', {
    templateUrl: 'views/order-detail.html',
    controller: 'OrderIdCtrl',
    resolve: { 
      order: function(Order, $routeParams) {
        Order.list().then(function(orders) {
          for(var i = 0; i < orders.length; i++) {
            if(orders[i].id === $routeParams.id) { 
              return orders[i];
            }
          }
          return null;
        });
      }
    }
  })

controllers 控制器

  .controller('OrderDetailsCtrl', function ($scope, $routeParams, $log, $rootScope, Order) {

        Order.list().then(function(orders) {
           $scope.detalleOrden = orders;
         }
        });

  .controller('OrderIdCtrl', function ($scope, $routeParams, $log, $rootScope, Order) {

    $scope.order = {};

    Order.list().then(function(orders) {
      for(var i = 0; i < orders.length; i++) {
        if(orders[i].id === $routeParams.id) { 
          $scope.order = orders[i];
        }
      }
    }, function() {
      $log('error');
    });
  });

and here the service 这里的服务

  .factory('Order', function ($q) {    
    return {
      list: function() {
        var deferred = $q.defer();

        deferred.resolve([{
          id: '12423',
          title: 'Detalles de la orden',
          supervisor: 'Someone',
          responsable: 'Someone Else',
          solicitante: 'Recope',
          unidadEjec: 'Grupo Planificador Belén'
        }, {
          id: '56456',
          title: 'Detalles de la orden',
          supervisor: 'Carlos Blabla',
          responsable: 'Alberto Blablo',
          solicitante: 'Recope',
          unidadEjec: 'Grupo VEINSA'
        }]);

        return deferred.promise;
      }
    };
  });

so, my issue: when I click on the title of the order, I am successfully redirected to the new view, but I am unable to visualize the content. 所以,我的问题是:当我单击订单标题时,我已成功重定向到新视图,但是无法看到内容。

You don't need to use any ng-repeat 您不需要使用任何ng-repeat

and just use order instead, look: 而是使用order ,请看:

            <table class="table">
                <tbody>
                    <tr>
                        <th>Supervisor:</th>
                        <td>{{order.supervisor}}</td>
                    </tr>
                    <tr>
                        <th>Responsable:</th>
                        <td>{{order.responsable}}</td>
                    </tr>
                    <tr>
                        <th>Solicitante:</th>
                        <td>{{order.solicitante}}</td>
                    </tr>
                    <tr>
                        <th>Unidad ejecutora:</th>
                        <td>{{order.unidadEjec}}</td>
                    </tr>
                </tbody>
            </table>

AFAIK you have to use variable order instead of list in table . AFAIK,您必须使用可变order而不是tablelist Am thinking that table is in detailed view. 我认为该table有详细视图。

For the uri /orders/:id you have order variable in controller OrderIdCtrl . 对于uri /orders/:id您在控制器OrderIdCtrl具有order变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM