2014-11-02 62 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 
相关问题