小编seb*_*987的帖子

AngularFire $使用Firebase参考中的变量从Array中删除项目不起作用

我一直在努力解决以下问题:

我正在尝试使用$ remove AngularFire方法从Firebase数组中删除"发布"项目,该方法已在Angular Service(Factory)中实现.这个帖子是'事件'的孩子,所以为了删除它,我必须将此服务传递给我想要删除帖子的相关事件的参数.

这是我的控制器:

app.controller('EventSignupController', function ($scope, $routeParams, EventService, AuthService) {
  // Load the selected event with firebase through the eventservice
  $scope.selectedEvent = EventService.events.get($routeParams.eventId);

  // get user settings
  $scope.user =  AuthService.user;
  $scope.signedIn = AuthService.signedIn;

  // Message functionality
  $scope.posts = EventService.posts.all($scope.selectedEvent.$id);

  $scope.post = {
    message: ''
  };
  $scope.addPost = function (){
    $scope.post.creator = $scope.user.profile.username;
    $scope.post.creatorUID = $scope.user.uid;
    EventService.posts.createPost($scope.selectedEvent.$id, $scope.post);
  };

  $scope.deletePost = function(post){
    EventService.posts.deletePost($scope.selectedEvent.$id, post);
    // workaround for eventService bug:
    // $scope.posts.$remove(post);
  };
});
Run Code Online (Sandbox Code Playgroud)

这是我的服务(工厂):

app.factory('EventService', function ($firebase, FIREBASE_URL) …
Run Code Online (Sandbox Code Playgroud)

angularjs firebase angularjs-service angularfire

1
推荐指数
1
解决办法
4628
查看次数