如何在firebase中绑定这些代码并进行自动同步,我想检查有人参加的被邀请者
var guestApp = angular.module("guestApp", []);
guestApp.controller('guestCtrl', function($scope) {
$scope.guests = ['jean','elie','tierry'];
$scope.addGuest = function(){
$scope.guests.push($scope.newGuest);
$scope.newGuest = '';
};
$scope.removeGuest = function(guest){
var i = $scope.guests.indexOf(guest);
$scope.guests.splice(i,1);
};
答案 0 :(得分:1)
首先,您需要确保HTML中包含这些库:
<!-- AngularJS -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.1.1/angularfire.min.js"></script>
至于代码本身:
您需要添加firebase模块依赖项:
var guestApp = angular.module("guestApp", ["firebase"]);
然后,在您的控制器中,您需要注入适当的firebase服务并记录身份验证:
guestApp.controller('guestCtrl', function($scope, $firebaseArray) {
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/guests");
之后,您可以将范围变量绑定到firebase引用:
$scope.guests = $firebaseArray(ref);
至于添加新项目:
$scope.addGuest = function(){
$scope.guests.$add($scope.newGuest);
$scope.newGuest = '';
};
并删除:
$scope.removeGuest = $scope.guests.$remove;
我想是的。顺便说一句。你可以在官方文档中阅读所有相关内容;) https://www.firebase.com/docs/web/libraries/angular/quickstart.html