AngularFire - How to define item ID for child template with ng-repeat?

前端 未结 2 1512
余生分开走
余生分开走 2021-01-23 23:09

Maybe my issue seems easy to resolve, but I\'ve this problem since a lot of hours : When I\'m in my dashboard, all data of my Firebase database are visible (With Ng-repeat). But

相关标签:
2条回答
  • 2021-01-23 23:51

    Can you please try the following set of codes, I've explained the changes in comments in Controller and added :id in App JS

    In App JS :

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

    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
    
      $scope.posts = Post.get(id); //call get() method of Post with the id retrieved
    
      $scope.post = {'title': '', 'content': ''};
    
      $scope.auth = Auth;
    
    0 讨论(0)
  • 2021-01-23 23:51

    you can use route provider to do that. I used that for my application and it works great.

    myApp.config( ['$routeProvider', function($routeProvider){
        $routeProvider.
            when('tabpost', {
                templateUrl: 'tabpost/id', 
                controller: 'PostCtrl' 
            });
    }]);
    
    0 讨论(0)
提交回复
热议问题