第一个参数包含在物业未定义

第一个参数包含在物业未定义

本文介绍了错误:Firebase.set失败:第一个参数包含在物业未定义“achv_img'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也跟着this帖子

有形式采用了棱角分明和火力,您可以注册,然后如果你点击绿色的,再加上它应该弹出的形式,上传按钮没有工作,当点击添加按钮,它给了我这个错误的错误:Firebase.set失败:第一个参数包含在财产achv_img未定义

控制器code:

  myApp.controller('MeetingsController',
  功能($范围,$ rootScope,$火力点,上载,
    CountMeetings,FIREBASE_URL){  VAR REF =新的火力地堡(FIREBASE_URL +'/用户/+
    。$ rootScope.currentUser的$ id +'/会议');  VAR meetingsInfo = $火力点(REF);
  。变种meetingsObj = meetingsInfo $ asObject();  meetingsObj。$()加载,然后(功能(数据){
    $ scope.meetings =数据;
  }); //确保会议数据加载  $ scope.addMeeting =功能(){
    meetingsInfo。$推({
      名称:$ scope.meetingname,
      说明:$ scope.meetingdescription,
      achv_type:$ scope.achvtype,
      achv_date:$ scope.achvdate,
      achv_img:$ scope.achvimg,
      日期:Firebase.ServerValue.TIMESTAMP
    })。然后(函数(){
      $ scope.meetingname ='';
      $ scope.achvtype ='';
      $ scope.meetingdescription ='';
      $ scope.achvdate ='';
      $ scope.achvimg = $ scope.meetingsInfoImgData;
    });
    Uploader.create($ scope.meetingsInfo);
  $ scope.handleFileSelectAdd =功能(EVT){
    变种F = evt.target.files [0];
    VAR读卡器=新的FileReader();
    reader.onload =(函数(theFile){
      复位功能(E){
        VAR filePayload = e.target.result;
        $ scope.meetingsInfoImgData = e.target.result;
        的document.getElementById('全景')SRC = $ scope.meetingsInfoImgData。
      };
    })(F);
    reader.readAsDataURL(F);
  };
  的document.getElementById('文件上传')的addEventListener('变化',$ scope.handleFileSelectAdd,假的)。
  }; // addmeeting  $ scope.deleteMeeting =功能(键){
    meetingsInfo $删除(键)。
  }; // deleteMeeting}); // MeetingsController


解决方案

reader.onload()您从文件中取的图像数据,并把它放入 $ scope.meetingsInfoImgData

  reader.onload =(函数(theFile){
  复位功能(E){
    VAR filePayload = e.target.result;
    $ scope.meetingsInfoImgData = e.target.result;
    的document.getElementById('全景')SRC = $ scope.meetingsInfoImgData。
  };
})(F);

我原来的答复然后使用它的等效的这个 $ scope.meetingsInfoImgData 后填充JavaScript对象并将其发送给火力地堡:

  $ scope.episode.img1 = $ scope.episodeImgData;
变种发作= $火力点(REF)$ asArray()。
。情节$添加($ scope.episode);

您code确实与 $ scope.meetingsInfoImgData 没有当它试图创建火力地堡的对象。你可能需要一个类似于 $ scope.episode.img1 = $ scope.episodeImgData; 在code太

I followed this post

Having form using angular and firebase achievementsapp.firebaseapp.com, you can register and then if you click on the green plus it should pop the form, upload button is not working and when click on Add button it gives me this error Error: Firebase.set failed: First argument contains undefined in property 'achv_img'

controller code:

myApp.controller('MeetingsController',
  function($scope, $rootScope, $firebase, Uploader,
    CountMeetings, FIREBASE_URL) {

  var ref = new Firebase(FIREBASE_URL + '/users/' +
    $rootScope.currentUser.$id + '/meetings');

  var meetingsInfo = $firebase(ref);
  var meetingsObj = meetingsInfo.$asObject();

  meetingsObj.$loaded().then(function(data) {
    $scope.meetings = data;
  }); //make sure meetings data is loaded

  $scope.addMeeting = function() {
    meetingsInfo.$push({
      name: $scope.meetingname,
      description: $scope.meetingdescription,
      achv_type: $scope.achvtype,
      achv_date: $scope.achvdate,
      achv_img : $scope.achvimg,
      date: Firebase.ServerValue.TIMESTAMP
    }).then(function() {
      $scope.meetingname='';
      $scope.achvtype = '';
      $scope.meetingdescription='';
      $scope.achvdate='';
      $scope.achvimg= $scope.meetingsInfoImgData;
    });
    Uploader.create($scope.meetingsInfo);


  $scope.handleFileSelectAdd = function(evt) {
    var f = evt.target.files[0];
    var reader = new FileReader();
    reader.onload = (function(theFile) {
      return function(e) {
        var filePayload = e.target.result;
        $scope.meetingsInfoImgData = e.target.result;
        document.getElementById('pano').src = $scope.meetingsInfoImgData;
      };
    })(f);
    reader.readAsDataURL(f);
  };
  document.getElementById('file-upload').addEventListener('change', $scope.handleFileSelectAdd, false);


  }; //addmeeting

  $scope.deleteMeeting = function(key) {
    meetingsInfo.$remove(key);
  }; //deleteMeeting

}); //MeetingsController
解决方案

In reader.onload() you take the image data from the file and put it into $scope.meetingsInfoImgData:

reader.onload = (function(theFile) {
  return function(e) {
    var filePayload = e.target.result;
    $scope.meetingsInfoImgData = e.target.result;
    document.getElementById('pano').src = $scope.meetingsInfoImgData;
  };
})(f);

My original answer then uses its equivalent of this $scope.meetingsInfoImgData later to populate the JavaScript object that it sends to Firebase:

$scope.episode.img1 = $scope.episodeImgData;
var episodes = $firebase(ref).$asArray();
episodes.$add($scope.episode);

Your code does nothing with $scope.meetingsInfoImgData when it tries to create the object in Firebase. You'll probably need something akin to $scope.episode.img1 = $scope.episodeImgData; in your code too.

这篇关于错误:Firebase.set失败:第一个参数包含在物业未定义“achv_img'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:31