I'm having an issue and I don't understand why it happens.
Part of my application is a blog using AngularFire
. When accessing a single blog post I use $getRecord(key)
method to retrieve data from Firebase.
The key parameter is retrieved via UI-Router's $stateParams
object.
I'm able to display datas in my post.single.html
view but when I refresh, the datas disappear and the $getRecord(Key)
returns null whereas the $stateParams
's value is correct.
Here's the code:
/* PostCtrl*/
'use strict';
angular
.module('meetTerry')
.controller('PostCtrl',['$scope','$stateParams','BlogFactory', function ($scope,$stateParams, BlogFactory) {
$scope.data = BlogFactory.loadPost($stateParams.postId);
}]);
/* BlogFactory*/
'use strict';
angular
.module('meetTerry')
.factory('BlogFactory', ['$firebaseArray',function ($firebaseArray) {
var postRef = new Firebase('https://firebase-forge/posts');
var postArray = $firebaseArray(postRef);
/***********************LOAD SINGLE***********************************/
var _loadPost = function (recordKey) {
var records = postArray.$getRecord(recordKey);
return records;
};
return {
loadPost: _loadPost
}
}]);
<div class="container" ng-controller="PostCtrl">
<div class="row">
<div class="small-12">
<h1>{{data.title}}</h1>
<p>{{data.content}}</p>
</div>
</div>
</div>
If anyone has a clue...