ReferenceError: $firebase is not defined

ReferenceError: $firebase is not defined

本文关键字:not defined is firebase ReferenceError      更新时间:2023-09-26

我正在尝试使用jasmine对该服务进行单元测试:-

我的单元测试是:-

describe('initial configuration for the test user', function () {
  beforeEach(function(){
      var config = {
            'Apache 404' : {
              content : {
                type : 'tip',
                template : 'yesNo',
                text : 'Are you searching for status code 404?',
                yesText : 'Try our more accurate <a href="https://www.loggly.com/docs/search-query-language/#field_names" target="_blank">field search</a>',
                attachTo : '#inputBox right',
                yesActions : {
                  0 : {
                      type : 'replaceSubstring',
                      target : '#inputBox',
                      value : 'apache.status:404',
                      match : '404'
                    }
                }
              },
              conditions : {
                0 : {
                    type : 'valueChange',
                    target : '#inputBox',
                    textMatch : '(^|([''s]+))404(([''s]+)|$)',
                    preventSubmit : true
                  },
                1 : {
                    type : 'contentPropertyLessThan',
                    propertyName : 'timesShown',
                    compareVal : 3
                  }
              }
            }
      };
      var clientName = 'testClient';
      var fireRef = new Firebase('https://luminous-inferno-1740.firebaseio.com/' + clientName);
      var fireSync = $firebase(fireRef);
      fireSync.$set({'config' : config});
      log.message = 'Resetting user data';
      $log.debug(log);
      userData.init(function(done) {
          done();
        });
  });
  it('should have a valid config', function () {
      expect(Object.keys(userData.getConfig()).length > 1);
    });

});

我收到一个错误:-

ReferenceError:$firebase未定义在对象处。

有人能帮我提供我的代码的工作示例并解释一下吗?

我也遇到了这个问题。我通过在控制器的参数中添加$firebaseArray解决了我的问题

.controller('ChatsCtrl',['$scope','$firebaseArray','$srootScope',……

需要注意的是,firebase已经更新,不再支持$firebase。您只能使用$firebaseArray或$firebaseObject来检索数据。