Firebase AngularFire .key() 方法产生 TypeError
Firebase AngularFire .key() method producing TypeError
我正在阅读 AngularFire 指南
https://www.firebase.com/docs/web/libraries/angular/guide.html#section-basics
当我尝试 运行 示例代码时
var app = angular.module("sampleApp", ["firebase"]);
app.controller("SampleController", function($scope, $firebase) {
var ref = new Firebase("https://<your-firebase>.firebaseio.com/");
var sync = $firebase(ref);
sync.$set({foo: "bar"});
sync.$push({hello: "world"}).then(function(newChildRef) {
console.log("added record with id " + newChildRef.key());
});
});
我在 Dev Tools 控制台中收到以下错误
TypeError: undefined is not a function
如果我 运行
console.log(newChildRef);
它产生以下内容
G {i: Gf, path: H, Ga: undefined, fa: undefined, za: undefined…}
Ea: undefined
Ga: undefined
fa: undefined
fb: undefined
i: Gf
path: Hz
a: undefined
__proto__: c
那里有很多未定义的东西。这里出了什么问题?
原来我不得不将我的 Firebase 更新到 2.0.4。使 .key()
方法起作用。问题已解决。
我正在阅读 AngularFire 指南
https://www.firebase.com/docs/web/libraries/angular/guide.html#section-basics
当我尝试 运行 示例代码时
var app = angular.module("sampleApp", ["firebase"]);
app.controller("SampleController", function($scope, $firebase) {
var ref = new Firebase("https://<your-firebase>.firebaseio.com/");
var sync = $firebase(ref);
sync.$set({foo: "bar"});
sync.$push({hello: "world"}).then(function(newChildRef) {
console.log("added record with id " + newChildRef.key());
});
});
我在 Dev Tools 控制台中收到以下错误
TypeError: undefined is not a function
如果我 运行
console.log(newChildRef);
它产生以下内容
G {i: Gf, path: H, Ga: undefined, fa: undefined, za: undefined…}
Ea: undefined
Ga: undefined
fa: undefined
fb: undefined
i: Gf
path: Hz
a: undefined
__proto__: c
那里有很多未定义的东西。这里出了什么问题?
原来我不得不将我的 Firebase 更新到 2.0.4。使 .key()
方法起作用。问题已解决。