【发布时间】:2015-05-17 07:28:43
【问题描述】:
我有一个service 有这个功能:
this.addSubject = function(categId, data){
$firebase(url.child('discussions').child(categId)).$push(data).then(function (newChildRef) {
console.log("added record with id " + newChildRef.key());
});
};
我在Controller 中调用该函数。但我想恢复新的 ID newChildRef.key(),以便在我的 Controller 中使用它。但如果我做出回报,那就什么都没有了。
有没有办法保存这个id?
或者是否可以在这个函数中调用我服务的其他函数?
【问题讨论】:
-
您能否仅返回
$firebase(url.child('discussions').child(categId)).$push(data)部分并从控制器中的.then(...)中访问密钥? -
请注意,AngularFire 是最近发布的 1.0.0,
$firebase现在已弃用。您可以改用$firebaseObject和$firebaseArray。 -
@bryan 我完全忘记尝试返回
firebase(url.child('discussions').child(categId)).$push(data)...但它有效!还有@SinanBolel,我知道$firebase现在已弃用,但我使用的是0.9.2 版本:)
标签: angularjs asynchronous firebase angularfire