2016-07-05 36 views
1

我在使用離子div的href時遇到了一些問題。如果我使用的離子列表中的所有工作良好:UI-Router離子卡列表

<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> 
+0

不應該使用'ng-href'嗎?另外,不確定你期望'href'屬性對'div'元素有什麼意義。 'ion-item'指令是不一樣的 - 如果提供了'href'屬性,它的內容將呈現在''元素中[[details](http://stackoverflow.com/a/29937692/1229023)) – raina77ow

回答

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你控制器

+0

謝謝你的主意))) – KingStakh

+0

@KingStakh你可以請答案接受嗎? :) 謝謝。 – adolfosrs

0

解決。這:

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

改成這樣:

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

並添加$狀態到我的控制器

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>