UI路由器离子卡列表

时间:2016-07-05 17:07:07

标签: angularjs ionic-framework angular-ui-router

我在离子div中使用href时遇到了一些问题。如果我使用离子列表,所有工作都很好:

<ion-item class="item-icon-right" ng-repeat="post in posts track by $index" href="#/app/posts/{{post.id}}" track>

但是当我尝试这个时,不要工作:

<div class="list card" ng-repeat="post in posts track by $index" href="#/app/posts/{{post.id}}" track></div>

3 个答案:

答案 0 :(得分:1)

href内无法使用

div。您可以使用ng-click解决方法并在控制器中处理它。

<div class="list card" ng-repeat="post in posts track by $index" ng-click="gotoPost(post.id)" track></div>

在您的控制器中:

$scope.gotoPost(postId){
    $location.path('/app/posts/'+postId);
}

请记住,您需要在控制器中注入$location

答案 1 :(得分:0)

解决。这样:

    $scope.gotoPost(postId){
    $location.path('/app/posts/'+postId);
}

更改为:

      $scope.gotoPost = function(postid){
      $state.go('app.post', {'postId': + postid});
  }

将$ state添加到我的控制器

答案 2 :(得分:0)

在每个地方声明仅用于路由的功能可能很麻烦。请改用此方法。

<div class="list">
  <a class="card item" 
     ng-repeat="post in posts track by $index" 
     ui-sref="post({id: 'post.id'})" >
    <div>{{post.content}}</div>
  </a>
</div>