Hi,
I’m new to ionic framework / ui-router and I have a routing problem.
I would appreciate any advice how to solve it.
In my Ionic app 'home’ page I have list view which fetch array from firebase and load last 10 objects - and it works fine.
Unfortunately, when I ‘click / tap’ to any list item, I got only empty object because (I assume) object id was not passed correctly.
In ‘article’ page (when I fetch it manually) article details are loaded fine. So the problem lays somewhere in routing / passing object id.
All I got in console is: Object {articleId: “”}
Here are my code snippets:
// HOME service and controller (works fine):
.factory(‘AllArticles’, [’$firebaseArray’, ‘FIREBASE_URL’, function($firebaseArray, FIREBASE_URL) {
var allArticlesRef = new Firebase(FIREBASE_URL + ‘articles/’).limitToFirst(10);
return $firebaseArray(allArticlesRef);
}])
.controller(‘homeCtrl’, function($scope, $ionicListDelegate, AllArticles){
$scope.allArticles = AllArticles;
})
// HOME html (not sure if link is configured as it should be)
{{article.title}}
{{article.description}}
// ARTICLE controller (probably where error is but i can’t figure out where)
.controller(‘articleCtrl’, function($scope, $http, $stateParams, $ionicListDelegate, $firebaseObject, FIREBASE_URL) {
$scope.currentArticle = $stateParams.articleId;
var currentArticleRef = new Firebase(FIREBASE_URL + ‘articles/’ + $scope.$stateParams);
var thisArticle = $firebaseObject(currentArticleRef);
$scope.article = thisArticle;
console.log($stateParams); // empty object
})
// ARTICLE ROUTE
.state(‘article’, {
url: ‘/article/:articleId’,
templateUrl: ‘templates/article.html’,
controller: ‘articleCtrl’
})