update()对象RTDB Firebase

问题描述 投票:0回答:2

为什么,当我尝试更新firebase中的实时数据库对象的titulo字段时,它是否会生成另一个字段?更新的正确方法是什么?我正在查看文档:https://github.com/angular/angularfire2/blob/master/docs/rtdb/objects.md,如果我的工作示例,他们在那里显示但是有一个列表。在这种情况下,我正在使用不同页面上的对象。有任何想法吗?

enter image description here

editar.component.html

<input type="text" #newtitulo [value]="titulo"/>
<button (click)="updateProyecto(key, newtitulo.value)">Update</button>

editar.component.ts

import { Component, OnInit } from '@angular/core';
import { AngularFireDatabase, AngularFireList, AngularFireObject } from 'angularfire2/database';
import { FirebaseService } from '../../../servicios/firebase.service';
import { ActivatedRoute } from '@angular/router';
import { Observable } from "rxjs/Observable";
import 'rxjs/add/operator/map';


@Component({
  selector: 'app-editar-proyecto',
  templateUrl: './editar-proyecto.component.html',
  styleUrls: ['./editar-proyecto.component.scss']
})
export class EditarProyectoComponent implements OnInit {


  proyectosRef: AngularFireObject<any>;
  proyecto: Observable<any[]>;
  id;
  titulo;
  destacado;
  descripcion;


  constructor(private fs: FirebaseService, private activateRoute: ActivatedRoute, private db: AngularFireDatabase) {
    this.proyectosRef = db.object('/proyectos');
    this.proyecto = this.proyectosRef.valueChanges();
  }

  ngOnInit() {
    this.id = this.activateRoute.snapshot.params['id'];
    this.fs.getProyectoDetalles(this.id).valueChanges().forEach(proyecto => {
      this.titulo = proyecto.titulo;
      this.destacado = proyecto.destacado;
      this.descripcion = proyecto.descripcion;
    });
  }

  updateProyecto(key: string, newTitulo: string) {
    this.proyectosRef.update({ titulo: newTitulo });
  }

}
angular firebase firebase-realtime-database
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.