私はこれらの機能を1つのコントローラに持っています。データを正常にインポートしましたが、$add
,$remove
、$edit
は使用できません。私は$RootScope
を使用します。保存されるアイテムは異なる状態にあり、コントローラが異なるためです。私はこれで新しいので、本当に助けに感謝します。AngularJSからFirebaseにアレイの新しいオブジェクトを追加、削除、編集する方法
angular
.module("")
.factory("Factory",function($http,$firebaseArray){
var ref = new Firebase('https://****.firebaseio.com/');
return{
ref:$firebaseArray(ref)
}
});
$scope.saveItems = function() {
console.log($scope.item);
$rootScope.items.push($scope.item);
$scope.item = [];
$mdSidenav('right').close();
}
$rootScope.removeItems = function(item) {
var index = $rootScope.items.indexOf(item);
$rootScope.items.splice(index, 1);
};
$rootScope.editItems=function(item){
$rootScope.editing = true;
$mdSidenav('right').open();
$rootScope.item=item;
$rootScope.saveEdit=function(){
$rootScope.editing=false;
$mdSidenav('right').close();
};
};