2014-11-02 66 views
1

我正在創建一個電子商務平臺,我有一個JSON產品清單,我正在閱讀。我想這個工作的方式是,我可以把這樣的事情:

{{products.products[parseInt(window.location.search)]}} 

我當前的代碼:

product.controller('products', ['$http', '$location', 
    function ($http, $location) { 

     var store = this; 


     console.log = $location.search(); 
     this.id = $location.search(); 

     store.products = []; 
     $http.get('http://adambkeim.com/js/data.json').success(function (data) { 
      store.products = data; 
     }).error(function (data, status, headers, config) { 
      console.log(status); 
      console.log(data); 
     }); 

    } 
]); 

然後在主要頁面:

<div class="container"> 

    <!-- Main component for a primary marketing message or call to action --> 
    <div class="jumbotron" ng-controller="products as products"> 
     <h1 style="color: green;">{{products.products[products.id].name}}</h1> 
     <p>{{products.products[0].desc}}</p> 
     <p>To see the difference between static and fixed top navbars, just scroll.</p> 
     <p> 
      <a class="btn btn-lg btn-success" href="/products/products.html?id=0" role="button">Learn More</a> 
     </p> 
    </div> 

</div> 

眼下,當我嘗試打印到控制檯時,parseInt或window.location都不會獲取任何值,但無法打印出任何內容。

+0

有啥你所面臨的問題? – AlexHv 2014-11-02 19:47:49

+0

應該真的在控制器中使用範圍,而不是在控制器上設置產品列表 – 2014-11-04 14:59:58

回答

0

我遇到了同樣的問題,現在你可以做這樣的:

$location.search().id 
相關問題