0
나는 firebaseListObservable리스트를 firebase에서 얻습니다. 내 개체는 다음과 같이 보입니다 :각도 Fire 2 : FirebaseListObservable 목록의 마지막 요소를 가져 오는 중.
{
"0" : {
"completed" : false,
"description" : "Grab the grocerry",
"id" : 25,
"status" : true,
"title" : "Grocerry"
},
"1" : {
"completed" : false,
"description" : "some task",
"id" : 26,
"status" : true,
"title" : "Complete this"
}
}
여기에 ForEach를 사용하여 FirebaseListObservable의 한 가지 방법으로 ID를 순차적으로 업데이트하고 싶습니다. 그러나 목록이 늘어남에 따라 비용이 너무 많이들 것입니다. 그래서 내 질문은 입니다. 1) Id를 가진 요소를 어떻게 찾을 수 있습니까? 2) ID를 순차적으로 업데이트하기 위해 ID의 마지막 색인을 얻는 방법.
내 코드 :
import { Component, OnInit } from '@angular/core';
import { todo } from '../shared/todo';
import {AngularFireDatabaseModule,AngularFireDatabase, FirebaseListObservable} from 'angularfire2/database';
import {AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
@Component({
selector: 'app-add-task',
templateUrl: './add-task.component.html',
styleUrls: ['./add-task.component.css']
})
export class AddTaskComponent {
newTask :todo = new todo();
finalObject : todo = new todo();
active: boolean = true;
todos: FirebaseListObservable<any[]>;
constructor(afAuth: AngularFireAuth, db: AngularFireDatabase) {
// this.user = afAuth.authState;
this.todos = db.list('todos');
}
onSubmit() {
console.log(this.newTask);
console.log(this.todos);
this.finalObject = {
'id' : 29,
'title' : this.newTask.title,
'description' :this.newTask.description,
'status':true,
'completed' :false
};
//this.todos.push(this.newTask);
this.newTask = new todo();
/* To reset the form*/
this.active=false;
setTimeout (()=> this.active=true,0);
/* To reset the form*/
}
}
수도 있었죠을() 메소드 아무튼 FirebaseListObservable리스트가 지원하지 않기 때문에 나에게 도움이되지 않는다. 다른 방법으로 제안 할 수 있습니까? – vaibhav
rxjs에서 가져 오는 경우입니다. – Chrillewoodz
업데이트 된 답변을 확인하십시오. – Chrillewoodz