也许我的问题似乎很容易解决,但是我在很长时间内遇到了这个问题:当我在我的信息中心时,我的Firebase数据库的所有数据都可见(使用Ng-repeat)。 但我找不到选择一个特定项目的解决方案,并在另一个页面中查看他的详细信息。
我在上面测试了这种方法并且我发现了这个错误"错误:无法解决'#/ tabpost'来自州&#; tabdash"。
这是HTML(这是一个例子):
<div ng-repeat="post in posts">
<div class="card" ui-sref="#/post/{id}">
<h1>{{post.title}}</h1>
<p>{{post.content}}</p>
</div>
</div>
在App JS中:
.state('tabpost', {
url: 'tabpost/id',
templateUrl: 'templates/tab-post.html',
controller: 'PostCtrl'
})
在Service JS中(在Post Factory中):
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 :(得分:0)
您需要在状态的URL中使用冒号为变量名称添加前缀。你的ui-router状态应该是
// set the variable if it was given, otherwise emtpy
$password = array_key_exists('password', $_POST) ? $_POST['password'] : '';
// confirm this is not an empty string
if ($password != '') {
// ... the rest
你应该像
一样链接到它 .state('tabpost', {
url: 'tabpost/:id',
templateUrl: 'templates/tab-post.html',
controller: 'PostCtrl'
});