Typerror: set is not a function with angularjs

Typerror: set is not a function with angularjs

我遇到了这个错误:

类型错误:fb.set 不是函数,angular.js:13550

当我尝试将数据发送到我的 firebase 数据库时。

我真的不明白我在这里遗漏了什么,我查看了文档,但一切看起来都不错。

var app = angular.module('app', ['firebase']);

app.controller("mainController", ["$scope", "$firebaseArray",
  function($scope, $firebaseArray) {

      var ref = new Firebase("https://burning-torch-4263.firebaseio.com/days");  
      fb =  $firebaseArray(ref); 

    $scope.reset = function() {  
    fb.set({
      monday: {
        name: 'Monday',
        slots: {
          0900: {
            time: '9:00am',
            booked: false
          },
          0110: {
            time: '11:00am',
            booked: false
          }
        }
      },
      tuesday: {
        name: 'Tuesday',
        slots: {
          0900: {
            time: '9:00am',
            booked: false
          },
          0110: {
            time: '11:00am',
            booked: false
              }
            }
          }
        });
    };    

  }

]);

对于 firebase 同步数组,您需要使用 .$add(newArrayItem) 而不是 set

适合我:

<!DOCTYPE html>
<html ng-app='app'>
<head>
  <meta name="description" content="AngularFire set data">
  <script src="https://cdn.firebase.com/js/client/2.2.6/firebase.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
  <script src="https://cdn.firebase.com/libs/angularfire/1.1.1/angularfire.min.js"></script>
  <meta charset="utf-8">
  <title>AngularFire set data</title>
</head>
<body ng-controller='MainCtrl'>
  <ol>
    <li ng-repeat='(id, day) in days'>{{day.name}} - {{id}}
      <ul>
        <li ng-repeat='slot in day.slots'>{{slot.time}}</li>
      </ul>
    </li>
  </ol>
</body>
</html>

还有 JavaScript

var app = angular.module('app', ['firebase']);

app.constant('FB_URL', 'https://Whosebug.firebaseio.com/36903668');
app.controller('MainCtrl', function(FB_URL, $scope, $firebaseArray, $firebaseObject) {

  var ref = new Firebase(FB_URL+"/days");  
  var fb =  $firebaseArray(ref); 
  $scope.days = fb;

  ref.set({
    monday: {
      name: 'Monday',
      slots: {
        0900: {
          time: '9:00am',
          booked: false
        },
        0110: {
          time: '11:00am',
          booked: false
        }
      }
    },
    tuesday: {
      name: 'Tuesday',
      slots: {
        0900: {
          time: '9:00am',
          booked: false
        },
        0110: {
          time: '11:00am',
          booked: false
        }
      }
    }
  });
});

Link 到 jsbin:http://jsbin.com/lofima/edit?html,js,output