首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularFire单个对象

AngularFire单个对象
EN

Stack Overflow用户
提问于 2013-04-29 08:21:34
回答 1查看 2.3K关注 0票数 9

在angularFire示例中,它展示了如何从firebase获取对象集合。

代码语言:javascript
复制
app.controller('ctrl', ['$scope', '$timeout', 'angularFireCollection',
  function($scope, $timeout, angularFireCollection) {    
    var url = 'https://ex.firebaseio.com/stuff';
    $scope.col = angularFireCollection(url);
  }
]);

如果只有一个对象呢?

我尝试了这样的东西:

代码语言:javascript
复制
  fb.child('stuff/'+id).on('value', function(snapshot) {
    $scope.obj = snapshot.val();
    console.log('hey got the value')
    console.log(snapshot.val())
  });

似乎不管用。控制台正确地输出了对象值,但是控制器没有更新。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-29 13:56:06

尝试使用常规的angularFire服务,并指定单个对象的类型:

代码语言:javascript
复制
app.controller('ctrl', ['$scope', '$timeout', 'angularFire',
  function($scope, $timeout, angularFire) {    
    var url = 'https://ex.firebaseio.com/stuff';
    angularFire(url, $scope, "obj", "");
  }
]);

注意第四个参数(“”表示字符串,也可以使用布尔值、数字、对象和数组)。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16269547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档