2016-10-27 29 views
0

你好人,所以我有一個控制器,我使用一些路由ID,所以我可以指示我的列表與它到另一個頁面。 我的控制器是這樣的:

RecordsControllers.controller('DetailsController', ['$scope', '$http','$routeParams', function($scope, $http, $routeParams) { 
    $http.get('js/data.json').success(function(data) { 
    $scope.records = data; 
    $scope.whichItem = $routeParams.itemId; 

     if ($routeParams.itemId > 0) { 
     $scope.prevItem = Number($routeParams.itemId)-1; 
    } else { 
     $scope.prevItem = $scope.records.length-1; 
    } 

    if ($routeParams.itemId < $scope.records.length-1) { 
     $scope.nextItem = Number($routeParams.itemId)+1; 
    } else { 
     $scope.nextItem = 0; 
    } 
    }); 
}]); 

使用ID路由到我的詳細信息頁面像我的列表發送:

<li class="chat cf animation" ng-repeat="item in records | filter: query | orderBy: chatsOrder:direction | limitTo:limit"> 
       <a href="#details/{{records.indexOf(item)}}" > 
<!--  <img ng-src="images/{{item.shortname}}_tn.jpg" alt="Photo of {{item.name}}">--> 
     <div class="info row" ng-repeat="error in item.errors"> 

      <div class="col s12"> 
      <div class="row"> 
      <div class="col s2 push10"><p class="type_message">Error Type&#58;</p></div> 

       <div class="col s10 pull2"> 
       <p >{{error.type}}</p> 

       </div> 
      </div> 
      </div> 





       <div class="col s12"> 

      <div class="row"> 


      <div class="col s2 push10"> 
       <p class="type_message"> Error Message&#58;</p> 
       </div> 

       <div class="col s10 pull2"><p>{{error.message}}</hp></div> 




        </div> 
      </div> 




<!--  <h3>{{item.gender}}</h3>--> 
     </div> 
        </a> 
      </li> 

,然後我用這個代碼,閱讀它的另一面

<section class="chatinfo"> 
    <div class="chat cf" ng-model="records"> 
    <a href="#/details/{{prevItem}}" class="btn btn-left">&lt;</a> 
    <a href="#/details/{{nextItem}}" class="btn btn-right">&gt;</a> 
    <h1>{{records[whichItem].errors.type}}</h1> 
    <div class="info"> 
     <h3></h3> 
     <img ng-src="images/{{records[whichItem].shortname}}_tn.jpg" alt="Photo of {{records[whichItem].name}}"> 
     <div class="bio"></div> 
    </div> 
    </div> 
    <a href="index.html">&laquo; Back to search</a> 
</section> 

我的問題,我不工作我不知道爲什麼那是我的JSON數據

[{ 
    "errors": [{ 
     "type": "ActionView::Template::Error", 
     "message": "undefined method `average_price' for nil:NilClass", 
     "backtrace": [{ 
      "file": "[PROJECT_ROOT]/app/views/quotes/show.html.haml", 
      "line": 1, 
      "function": "_app_views_quotes_show_html_haml___1123891298168566182_70087807002600" 
     }] 
    }]}] 

我的問題是在這裏

<section class="chatinfo"> 
    <div class="chat cf" ng-model="records"> 
    <a href="#/details/{{prevItem}}" class="btn btn-left">&lt;</a> 
    <a href="#/details/{{nextItem}}" class="btn btn-right">&gt;</a> 
    <h1>{{records[whichItem].errors.type}}</h1> 
    <div class="info"> 
     <h3></h3> 

     <div class="bio"></div> 
    </div> 
    </div> 
    <a href="index.html">&laquo; Back to search</a> 
</section> 

我不能讀取數據

回答

0

好傢伙,我發現我怎麼能做到這一點

<h1 ng-repeat="item in records[whichItem].errors"> 

     {{item.type}} 

     </h1> 
相關問題