2015-07-11 49 views
0

也許我的問題看起來很容易解決,但自從很多小時後我遇到了這個問題:當我在儀表板中時,所有數據我的Firebase數據庫可見(使用Ng-repeat)。 但我找不到解決方案來選擇一個特定的項目,並在另一個頁面中查看他的詳細信息。AngularFire - 錯誤:無法從狀態'tabdash'解析'#/ tabpost'

我已經測試了上面的這個方法,並且我有這個錯誤「錯誤:無法從狀態'tabdash'解析'#/ tabpost'。

這是HTML(這是一個例子):

<div ng-repeat="post in posts"> 

<div class="card" ui-sref="#/post/{id}"> 
<h1>{{post.title}}</h1> 
<p>{{post.content}}</p> 
</div> 

</div> 

在應用JS:

.state('tabpost', { 
    url: 'tabpost/id', 
    templateUrl: 'templates/tab-post.html', 
    controller: 'PostCtrl' 
    }) 

在服務JS(中郵廠):

myApp.factory("Post", ["$firebaseArray", "$firebaseObject", function($firebaseArray, $firebaseObject) { 
var postRef = new Firebase('https://myApp.firebaseio.com/Posts/'); 
var userRef = new Firebase('https://myApp.firebaseio.com/Users/'); 
var posts = $firebaseArray(postRef); 

    var Post = { 

     all: posts, 

     get: function (postKey){ 
      var postId = $firebaseObject(postRef); 
       return $firebaseObject(eventRef.child('Posts').child(postId).child(userid)); 

       } 
      , 
     add: function (post){ 
      var postId = $firebaseArray(postRef, userRef); 
      event.userid = userRef.getAuth(); 
       return postId.$add(post); 
       } 
     } 
     return Post; 

}]); 

我PostCtrl:

myApp.controller('PostCtrl', ['$ionicFrostedDelegate', '$ionicScrollDelegate','$state','$scope', 'Post', 'Auth', '$firebaseObject', '$firebaseArray', '$routeParams', function($ionicFrostedDelegate, $ionicScrollDelegate, $state,$scope, Post, Auth, $firebaseObject, $firebaseArray, $routeParams) { 

    var PostRef = new Firebase("https://myApp.firebaseio.com/Posts"); 

var id = $routeParams.id; //get the id from url, $routeParams is injected in controller 

    $state.go('tabpost', { 
    id: $scope.id 
    }); 

    $scope.posts = Post.get(id); //call get() method of Post with the id retrieved 

    $scope.post = {'title': '', 'content': ''}; 

    $scope.auth = Auth; 

PS:花了3天時間才嘗試了大量過時的教程,我相信解決方案不會那麼簡單。

我昨天和之後已經發布了三個類似的問題,但每個建議的解決方案都沒有奏效。我將非常感謝能幫助我走出僵局的人。

我還是有點麻煩jsFiddle答應我會學會使用它,一旦我會解決這個問題。

謝謝你給我時間

+0

你可以發佈更多的'app.js'或創建codepen/plunker /一些代碼的例子嗎?如果您使用的是Ionic的'ui-router',那麼您應該使用'$ stateParams',而不是'$ routeParams',並且您的狀態定義中的url應該像這樣:'url:'tabpost /:id''(注意id之前的冒號)。請參閱[本博客](http://www.gajotres.net/ionic-framework-tutorial-5-master-detail-pattern/)瞭解更多信息。 – brandyshea

+0

謝謝,我會測試它,我回來了。你想要我所有的路線提供者嗎? – PositivProd

+0

'ui-sref =「#/ post/{id}」'不正確。你需要傳遞狀態名稱,而不是散列,例如'ui_sref="home({foo:'fooVal1',bar:'barVal1'})">'..看到這個http:// stackoverflow.com/a/25647714/1516309 – jakeed1

回答

0

你需要在你的國家的URL冒號前綴的變量名。你的UI路由器狀態應該是

.state('tabpost', { 
    url: 'tabpost/:id', 
    templateUrl: 'templates/tab-post.html', 
    controller: 'PostCtrl' 
    }); 

,你應該鏈接到它就像

<div class="card" ui-sref="tabpost/{id}"> 
+0

我試過,但我有同樣的錯誤:錯誤:無法解析'tabpost/{id}'狀態'tabdash' – PositivProd

+0

看看你的控制檯中的DOM,{id}​​實際上是注入還是保持爲字符串「{id}」? –

+0

總是字符串ID .. – PositivProd