【问题标题】:$firebaseArray is not a function?$firebaseArray 不是函数?
【发布时间】:2015-12-24 10:49:56
【问题描述】:

我正在创建一个 firebase 博客应用。我的控制器遇到问题TypeError: $firebaseArray is not a function 在整个应用程序的整个范围内,我一直在使用 $firebaseArray。我不知道我是怎么弄坏的。我可以将代码显示给我的控制器。

 app.controller('postController',["$scope", "$location","$routeParams","Blog","FBURL","Auth","authDataSrvc", "$firebaseObject", "$firebaseArray","FilePicker", "$window", function($scope,$location,$routeParams,Blog,FBURL,$firebaseArray,$firebaseObject,FilePicker,$window,Auth,authDataSrvc){


$scope.posts = Blog.allPosts; //All blog posts
var postId = $routeParams.postId;

if(postId){
  $scope.selectedPost = getPost(postId); // gets unique object based on its id with get post function
}

function getPost(postId){
  var ref = new Firebase(FBURL + "/" + postId);
  return $firebaseArray(ref);
}


$scope.addPost = function(newpost){
  Blog.addPost($scope.newpost);
  $location.path('/'); //redirects to home page
  console.log(newpost);
  console.log($scope.posts); // all posts
  $scope.newpost ={}; //reset the message


};

$scope.currentPost = function(postId){
  Blog.getPost(postId);
  console.log(postId);
};

$scope.editPost = function(post){
  $scope.selectedPost.$save(post);
  $location.path('/');
};

$scope.files = [];


$scope.pickFile = function(){
    FilePicker.pickMultiple(
        {
          mimetype: 'image/*',
          maxFiles: 4
        },
        $scope.onSuccess
    );
};

$scope.onSuccess = function(Blobs,newpost){
  $scope.files.push(Blobs); //push to filepicker

  var imageURLs = []; //new image urls array
  Blobs.forEach(function(file){
    imageURLs.push(file.url); //inserts Blob.urls to imageURLs array
  });
  $scope.newpost['photo'] = imageURLs; //adds photo urls array to newpost.photo which stores to firebase 'newpost object'
  console.log(Blobs.url);
  $window.localStorage.setItem('files', JSON.stringify(Blobs.url));
};

// 评论区

  /*  {

  }*/

$scope.createComment = function(post, message){

  var profilePic;
  var profileName;
  /* Check to see social media provider before pushing that information */
  if($scope.authData.provider === 'facebook'){
    profilePic = $scope.authData.facebook.profileImageURL;
    profileName = $scope.authData.facebook.displayName;
  }
  else if($scope.authData.provider === 'google'){
    profilePic = $scope.authData.google.profileImageURL;
    profileName = $scope.authData.google.displayName;
  }
  //console.log(profilePic,profileName);

  var ref = new Firebase(FBURL + "/" + postId + "/comments/");
  var fireCommentArray = $firebaseArray(ref);
  return fireCommentArray.$set(
    {
      text: $scope.message.text,
      pic: $scope.profilePic,
      name: $scope.profileName
    }
  ),
  $scope.message = '';
};



$scope.removeComment = function(post, message) {
  var commentForDeletion = new Firebase(FBURL + "/" + postId + "/comments/" + message.$id);
  commentForDeletion.$remove();
};

现在它在 getPost 函数 $scope.addCommentFunction 上出错,它们都在使用 $firebaseArray.$add() 调用。

我的应用也有独立的服务和指令,但一切似乎都完好无损。

【问题讨论】:

    标签: angularjs firebase angularfire


    【解决方案1】:

    您的$firebaseArray 对象作为第9 个参数被注入,但变量$firebaseArray 是第6 个参数。

    试试这个:

    app.controller('postController', [
      "$scope", "$location", "$routeParams", "Blog", "FBURL", 
      "Auth", "authDataSrvc", "$firebaseObject", "$firebaseArray", "FilePicker", 
      "$window", 
      function(
        $scope, $location, $routeParams, Blog, FBURL, 
        Auth, authDataSrvc, $firebaseObject, $firebaseArray, FilePicker, 
        $window
    ){
    

    ...如果您不通过压缩器或混淆器破坏变量名称,则完全删除 ["$scope", "$location", "$routeParams", "Blog"...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多