import { Injectable } from '@angular/core';
import { AngularFirestore} from 'angularfire2/firestore';
import { map, take } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ItemService {
constructor(private afs: AngularFirestore) { }
create(item) {
return this.afs.collection('items').add(item);
}
getAll() {
return this.afs.collection('items').snapshotChanges().pipe(
take(1),
map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
});
})
);
}
get(itemId) {
return this.afs.doc(`items/${itemId}`);
}
}
item = {};
constructor(
private router: Router,
private afs: AngularFirestore,
private route: ActivatedRoute,
private itemService: ItemService) {
const id = this.route.snapshot.paramMap.get('id');
if (id) {this.itemService.getItem(id).snapshotChanges().pipe(take(1), map(p => this.product = p));
}
my
item.component.html
<input #title="ngModel" [(ngModel)]="item.title" name="title" type="text" id="title" class="form-control">
in my my-item.component.html i have a link
<a [routerLink]="['/my/items', p.id]">Edit</a> when i click
edit sends me back to items.component with ID od item that a click in
the URL, but never get data from firestore itmes in the input fied
Someone can hellp?