Я работаю над угловым проектом с Google Cloud Firestore
.Тогда у меня есть вопрос.Как удалить подпункт коллекции.Например, я хочу удалить адрес в следующем.Я использую ng2-smart-table
в качестве таблицы.Я добавил его в manufacture
компонент.
manufacturing.service.ts
import { Injectable } from '@angular/core';
import { Manufacture } from './manufacture.model';
import { AngularFirestore } from '@angular/fire/firestore';
import { from } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ManufactureService {
manufacture: Manufacture;
constructor(private firestore: AngularFirestore) {}
addManufacture(object) {
return from(
this.firestore
.collection('Manufacture')
.doc('manufacture')
.set(object)
);
}
getManufacture() {
return this.firestore
.collection('Manufacture')
.doc('manufacture')
.snapshotChanges();
}
deleteManufacture() {
this.firestore
.collection('Manufacture')
.doc('manufacture')
.delete();
}
show() {
return this.firestore
.collection('Manufacture')
.doc('manufacture')
.collection('manufact')
.doc('0')
.snapshotChanges();
}
}
manufacturing.component.ts
import { Component, OnInit } from '@angular/core';
import { ManufactureService } from './manufacture.service';
import { Manufacture } from './manufacture.model';
@Component({
selector: 'ngx-manufacture',
styles: [],
template: `
<ng2-smart-table
(createConfirm)="addData($event)"
(deleteConfirm)="deleteData($event)"
[settings]="settings"
[source]="manu"
>
</ng2-smart-table>
`
})
export class ManufactureComponent implements OnInit {
manu: Manufacture[] = [];
constructor(private service: ManufactureService) {}
ngOnInit() {
this.service.getManufacture().subscribe(arr => {
let manu_list = arr.payload.get('manufact');
if (manu_list) {
this.manu = manu_list;
}
});
}
settings = {
add: {
addButtonContent: '<i class="nb-plus"></i>',
createButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>',
confirmCreate: true
},
edit: {
editButtonContent: '<i class="nb-edit"></i>',
saveButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>'
},
delete: {
deleteButtonContent: '<i class="nb-trash"></i>',
confirmDelete: true
},
columns: {
shopname: {
title: 'Shop Name'
},
ownername: {
title: 'Owner Name'
},
nic: {
title: 'NIC'
},
contactno: {
title: 'ContactNo'
},
address: {
title: 'Address'
},
email: {
title: 'Email'
}
}
};
addData(data) {
alert(data.newData.email);
this.manu.push(data.newData);
console.log(this.manu);
this.service.addManufacture({ manufact: this.manu }).subscribe(next => {
data.confirm.reject();
});
}
deleteData(data) {
alert(data.emial);
this.service.deleteManufacture();
}
}
Тогда как я это сделаю.Однажды я попробовал следующий код.но не успех
deleteManufacture() {
this.firestore
.collection('Manufacture')
.doc('manufacture')
.delete();
}
Любой может мне помочь