-2
I’m with an angular project and I’m using firebase cloud firestore as a database but I’m having a hard time using it because I have a collection called feed and within this collection I have several items and I need to pick only one item using its key however all the methods I tried didn’t work.
my service:
import { Injectable } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
@Injectable()
export class TestService {
constructor(private firestore: AngularFirestore) { }
/* create_NewIcecream : Cria um novo registro na coleção especificada usando o método add */
criar_novo_user(record) {
return this.firestore.collection('user').add(record);
}
/*read_Icecream: Chama o método snapshotChanges , que obterá registros e também será registrado para receber atualizações */
read_userPrincipal(){
return this.firestore.collection('user').snapshotChanges();
}
read_feddUser(key:string){
return this.firestore.collection('feed').get;
}
update_like(recordID,record) {
return this.firestore.doc('feed/' + recordID).update(record);
}
carregar_publicacao(){
return this.firestore.collection('feed').snapshotChanges();
}
}
my component
import { Component, OnInit, Input } from '@angular/core';
import { Publicacao } from './publi.model';
import { TestService } from 'src/app/test.service';
@Component({
selector: 'app-publi',
templateUrl: './publi.component.html',
styleUrls: ['./publi.component.css']
})
export class PubliComponent implements OnInit {
@Input() publicacao: Publicacao
constructor(private testeService: TestService) { }
ngOnInit(){}
like(item){
let arrey;
arrey = this.testeService.read_feddUser(item.token)
console.log(arrey)
}
}
in that like function is where I need to read only the item with its key.
i put the function as you showed there and it from the compilation error
– jvl
read_feddUser(key:string){ Return firebase.firestore(). Collection('feed'). doc(key). get(); }
– jvl
import * as firebase from firebase;?
– jvl
ERROR in . /firebase 37:8 Module parse failed: Unexpected token (37:8) You may need an appropriate Loader to Handle this file type, Currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders | }) | console.log(this.publicacoes) > } | |
– jvl
in your case should be
this.firestore.collection('feed').doc(key).get();
corrected in response.– tvdias
worked @jvl?
– tvdias
thus putting the error actually some of the service but error in the component in the function then
– jvl
https://firebase.google.com/docs/firestore/query-data/get-data#get_a_document
– tvdias
@jvl check how it is in the documentation, this link above
– tvdias
but doing like this error also because it says that get is not a function and then is also not a function.
– jvl
Return this.firestore.Collection('feed'). doc(key). get(); if I leave my service function so and the Component function so Let feed ; feed = this.testeService.read_feddUser(item.token) console.log(feed) it returns me an observable as I manage to access the properties in that observable in the course I did I understood almost nothing of Observable
– jvl