var myapp = angular.module('point',['firebase']);
myapp.factory('fact', function ($firebaseArray)
{
var ref = new Firebase("https://myangularl.firebaseio.com");
return $firebaseArray(ref);
})
myapp.controller('financeCtrl', function ($scope,fact)
{
$scope.students = fact;
$scope.add = function (data)
{
var name = $scope.name;
var major = $scope.major;
$scope.students.$add({
name: name, major: major
});
$scope.name="";
$scope.major="";
},
$scope.remove = function(data)
{
$scope.students.$remove(data);
}
});
i am new to angular and firebase and i am having trouble getting my data from firebase so my user can edit and update. My remove and add functions are working fine, but i cannot seem to understand how the concept of updating. any help would be appreciated.
我是角度和firebase的新手,我无法从firebase获取数据,因此我的用户可以编辑和更新。我的删除和添加功能工作正常,但我似乎无法理解如何更新的概念。任何帮助,将不胜感激。
1 个解决方案
#1
0
$firebaseArray automatically keeps local array in sync with any changes made to the remote database. To make change to to remote database, you can use $add(), $remove(), and $save() etc.
$ firebaseArray自动使本地数组与对远程数据库所做的任何更改保持同步。要更改到远程数据库,可以使用$ add(),$ remove()和$ save()等。
Below are two ways to update the local array to Firebase database:
以下是将本地阵列更新为Firebase数据库的两种方法:
<li ng-repeat="student in students">
<input type="text" ng-model="student.name" ng-change="students.$save(student)" />
</li>
Another way
<li ng-repeat="student in students">
<input type="text" ng-model="student.name" ng-change="update(student)" />
</li>
$scope.update = function(item) {
return $scope.students.$save(item);
},
#1
0
$firebaseArray automatically keeps local array in sync with any changes made to the remote database. To make change to to remote database, you can use $add(), $remove(), and $save() etc.
$ firebaseArray自动使本地数组与对远程数据库所做的任何更改保持同步。要更改到远程数据库,可以使用$ add(),$ remove()和$ save()等。
Below are two ways to update the local array to Firebase database:
以下是将本地阵列更新为Firebase数据库的两种方法:
<li ng-repeat="student in students">
<input type="text" ng-model="student.name" ng-change="students.$save(student)" />
</li>
Another way
<li ng-repeat="student in students">
<input type="text" ng-model="student.name" ng-change="update(student)" />
</li>
$scope.update = function(item) {
return $scope.students.$save(item);
},