我有一个json集合,我已经上传到我的firebase,这些网站和工具通过位于前者的数组相关联,指向后者中的键
"sites": {
"s001": {
"name": "ACT-105",
"description": "Intro Accounting",
"type": "course",
"thumbnail": "debate",
"toolCount": 4,
"tools" : ["t001","t002","t003"]
},
"s002": {
"name": "ART-201",
"description": "Pottery Lab",
"type": "course",
"thumbnail": "sculpture",
"toolCount": 4,
"tools" : ["t001","t002","t003","t004"]
},
"tools": {
"t001": {
"name": "main-tool",
"title": "Home",
"description": "Main tool",
"thumbnail": "home.jpeg"
},
"t002": {
"name": "announce-tool",
"title": "Announcements",
"description": "System Announcements",
"thumbnail": "announcements.jpeg"
},
Run Code Online (Sandbox Code Playgroud)
我打开一个网址并承诺; 然后在数组中获取当前站点及其相关工具数组,然后打开另一个循环并获取所有相关工具的承诺.从警报中,它似乎只抓取一个工具然后退出.
angular.module("foo", ["firebase"]).
controller("MyCtrl", ["$scope", "angularFire", function($scope, angularFire) {
var dbRef = "https://sampledb.firebaseio.com";
var siteRef = …Run Code Online (Sandbox Code Playgroud) 出于某种原因,当我尝试使用它时,$ firebase是未定义的.我对Angular很新,所以我猜测我分割文件的方式只有一些脱节.如果它只在一个HTML页面中,我可以让所有代码正常工作,但我想将它全部拆分,因为我的应用程序将有不同的页面.
controllers.js
angular.module('myApp.controllers', ['firebase']).
controller('StoryController', [function($scope, $firebase) {
var storiesRef = new Firebase(FIREBASE_URL);
$scope.stories = $firebase(storiesRef);
$scope.addStory = function(e) {
if (e.keyCode != 13) return;
$scope.stories.$add({title: $scope.title, text: $scope.text});
$scope.text = "";
}
}]);
Run Code Online (Sandbox Code Playgroud)
app.js
angular.module('myApp', [
'ngRoute',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/stories', {templateUrl: 'partials/stories.html'});
$routeProvider.when('/addStory', {templateUrl: 'partials/addStory.html', controller: 'StoryController'});
$routeProvider.otherwise({redirectTo: '/'});
}]);
Run Code Online (Sandbox Code Playgroud)
编辑:忘记包含错误.
TypeError: undefined is not a function
at new <anonymous> (http://localhost:8000/app/js/controllers.js:8:22)
at d (http://localhost:8000/app/lib/angular/angular.min.js:30:452)
at Object.instantiate (http://localhost:8000/app/lib/angular/angular.min.js:31:80)
at http://localhost:8000/app/lib/angular/angular.min.js:62:23
at link (http://localhost:8000/app/lib/angular-route/angular-route.min.js:7:208) …Run Code Online (Sandbox Code Playgroud) 假设我有一系列项目:
var itemsRef = new Firebase("https://example.firebaseio.com/items");
$scope.items = $firebase(itemsRef);
Run Code Online (Sandbox Code Playgroud)
我们$add一个项目:
$scope.items.$add($scope.item);
Run Code Online (Sandbox Code Playgroud)
我知道在进入Firebase集合之前,ref会生成客户端.
添加商品后如何获得该商品? 例如 -Jx8363hdu12
AngularFire 0.6.0
我正在尝试为我的Yeoman,AngularJS应用程序设置firebase,angularfire.我在这里遵循了这个教程(https://www.firebase.com/tutorial/#tutorial/angular/0),但我一直在学习
Uncaught Error: [$injector:modulerr] Failed to instantiate module MyApp due to:
Error: [$injector:modulerr] Failed to instantiate module firebase due to:
Error: [$injector:nomod] Module 'firebase' is not available! You either misspelled the m...<omitted>...1)
Run Code Online (Sandbox Code Playgroud)
我如何通过这个?
我相信这是教程中的这两行,它说它为我们下载了firebase,但我可能会把它放在错误的地方.我尝试将它放在head标签之间,正好是bower组件,以及我所有脚本旁边
<script src='https://cdn.firebase.com/js/client/1.0.15/firebase.js'></script>
<script src='https://cdn.firebase.com/libs/angularfire/0.8.0/angularfire.min.js'></script>
Run Code Online (Sandbox Code Playgroud) 我正在开发一个带有angularjs和firebase的webapp,而我能够保存新的记录,我无法使用someReference删除记录.$ remove(varkey); 承诺返回:'无效记录; 找不到钥匙'但是同样的参考可以正常保存物品.我修改了varkey上的空格但是一切似乎都失败了,我正在使用bower依赖,哪个版本是"angularfire":"~0.8.0"根据bower.json
到目前为止,我的服务代码是:
var testRef = new Firebase('https://test-list.firebaseio-demo.com/list'),
testRefArr = $firebase(testRef).$asArray();
console.log(testRefArr);
var testpromise = testRefArr.$remove('-JXdmpQbeCAEBl7I3YVO');
testpromise.then(function (response) {console.log(response);}, function (error) {console.log('err: '+error);});
Run Code Online (Sandbox Code Playgroud)
这是这篇文章的演示基础:AngularJS与AngularFire 0.5.0 - $ remove item不起作用, 但它们似乎使用的是0.5.0版,我使用的是0.8.0.有任何想法吗?
我正在尝试获取属于特定用户的所有鲜花数据,在本例中为simplelogin:69.
我开始从用户那里获取所有花键,如下所示:
/users/simplelogin:69/flowers/
var ref = new Firebase("https://URL.firebaseio.com/users/"+uid+"/flowers");
var sync = $firebase(ref);
Run Code Online (Sandbox Code Playgroud)
现在我很难找到一个干净的方法来获取所有花卉数据通过循环thrue每个花键来自simplelogin:69没有循环thrue每个键/ flowers /(在下面的示例我只有三个花键但在生产中我可能有10k ).
我尝试过FirebaseIndex和firebase-util,但无法让它正常工作.有没有人有任何提示或任何东西?我已经在堆栈上阅读了以前的帖子,但大多数似乎已经过时或者不适合我的目标.真的可以用AngularFire来解决任何问题.
亲切的问候,伊莱亚斯
{
"flowers" : {
"-JiU57sFAfQwYtIq-LCl" : {
"image" : "test",
"name" : "test",
"type" : "Roses",
"uid" : "simplelogin:69"
},
"-JiU9-3ajlnFLpyUmBvL" : {
"image" : "dasdasd",
"name" : "sadasdas",
"type" : "Roses",
"uid" : "simplelogin:69"
},
"-JiUF-mioK3jQCYy6ZiG" : {
"image" : "ss",
"name" : "ss",
"type" : "Lilies",
"uid" : "simplelogin:69"
}
},
"users" : {
"simplelogin:69" : {
"flowers" : { …Run Code Online (Sandbox Code Playgroud) 我一直在努力解决以下问题:
我正在尝试使用$ remove AngularFire方法从Firebase数组中删除"发布"项目,该方法已在Angular Service(Factory)中实现.这个帖子是'事件'的孩子,所以为了删除它,我必须将此服务传递给我想要删除帖子的相关事件的参数.
这是我的控制器:
app.controller('EventSignupController', function ($scope, $routeParams, EventService, AuthService) {
// Load the selected event with firebase through the eventservice
$scope.selectedEvent = EventService.events.get($routeParams.eventId);
// get user settings
$scope.user = AuthService.user;
$scope.signedIn = AuthService.signedIn;
// Message functionality
$scope.posts = EventService.posts.all($scope.selectedEvent.$id);
$scope.post = {
message: ''
};
$scope.addPost = function (){
$scope.post.creator = $scope.user.profile.username;
$scope.post.creatorUID = $scope.user.uid;
EventService.posts.createPost($scope.selectedEvent.$id, $scope.post);
};
$scope.deletePost = function(post){
EventService.posts.deletePost($scope.selectedEvent.$id, post);
// workaround for eventService bug:
// $scope.posts.$remove(post);
};
});
Run Code Online (Sandbox Code Playgroud)
这是我的服务(工厂):
app.factory('EventService', function ($firebase, FIREBASE_URL) …Run Code Online (Sandbox Code Playgroud) 我正在使用firebase进行项目,我正在尝试从数据库中获取所有对象,我正在运行这段代码来获取它们:
var ref = new Firebase("https://<fire-base-database>.firebaseio.com/games");
$scope.games = $firebaseArray(ref);
Run Code Online (Sandbox Code Playgroud)
我正确地获取对象,但当我尝试访问他们的ID时,.$id我没有收到任何数据...
是否有任何方法可以获得对象的唯一ID(看起来像什么JlTq-W2RtWpOuKb2_Gp)?当有人点击它时,我需要它来显示项目的详细视图.
先感谢您!
我想做什么:
我想在我的主页上输出书籍节点中的所有书籍.我需要的是一个包含书籍节点中所有书籍的对象数组,以便我可以使用AngularJs中的ng-repeat指令循环遍历它们.在下面的代码中,当我控制台记录数据时,我得到一个对象的对象,它不能与ng-repeat一起使用.我遇到的另一个问题是当我尝试将$ scope.allBooks变量输出到页面时,没有任何内容出现.谁能帮我这个?
使用Javascript SDK而非Angularfire https://firebase.google.com/docs/
// Main Controller
firebase.database().ref('books').on('value', function(snapshot) {
var data = snapshot.val();
$scope.allBooks = data;
console.log(data);
});
// Book Node in Firebase
books : {
id : {
title: 'The Hunger Games',
author: 'Suzanne'
},
id : {
title: 'Harry Potter and the Order of the Phoenix',
author: 'J.K.'
}
}
Run Code Online (Sandbox Code Playgroud) javascript angularjs firebase angularfire firebase-realtime-database
我正在使用Angular 2和AngularFire与FirebaseObservable来获取"喜欢"列表,使用以下代码:
likes: FirebaseListObservable<number[]>;
constructor(private angularFire: AngularFire) {
this.likes = angularFire.database.list('/likes');
}
onClicked() {
this.likes.push({'item': 'new like'})
}
Run Code Online (Sandbox Code Playgroud)
我正在使用各种循环
<ul>
<li *ngFor="let like of likes | async">
{{ like.item }}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我想得到所有项目的计数,但以下是失败:
<span>{{ likes.length }}</span>
Run Code Online (Sandbox Code Playgroud)
有谁知道如何实现这一目标?
谢谢!
firebase angularfire firebase-realtime-database angularfire2 angular
angularfire ×10
firebase ×10
angularjs ×7
javascript ×4
angular ×1
angularfire2 ×1
denormalized ×1
promise ×1
yeoman ×1