所以我已将业务信息上载到数据库(createItemAuth()
),并且我正试图将数据库中的子项将卡车和拖车上载到公司,但这是行不通的。那就是我的尝试:
export interface Trucks {
name: string;
}
export interface Trailers {
name: string;
}
export interface Data {
name: string;
address: string;
address2: string;
pscode: string;
ccode: string;
name2: string;
trucks: Trucks;
trailers: Trailers;
}
export class BackService {
constructor(private afDatabase: AngularFireDatabase, private afAuth: AngularFireAuth ) {
this.busCollection = this.afDatabase.list(`imones`);
}
busines = {} as Data;
createItemAuth() {
this.afAuth.authState.subscribe(auth => {
this.afDatabase.object(`${auth && auth.email && auth.uid}/company/`).update(this.busines)
});
}
createTruckAuth() {
this.afAuth.authState.subscribe(auth => {
this.afDatabase.list(`${auth && auth.email && auth.uid}/company/trucks/`).push(this.busines.trucks)
});
}
createTrailAuth() {
this.afAuth.authState.subscribe(auth => {
this.afDatabase.list(`${auth && auth.email && auth.uid}/comapny/trails/`).push(this.busines.trailers)
});
}
创建HTML:
<input [(ngModel)]="back.busines.name" type="text">
<input [(ngModel)]="back.busines.address" type="text">
<input [(ngModel)]="back.busines.address2" type="text">
<input [(ngModel)]="back.busines.trucks.name" type="text">
<input [(ngModel)]="back.busines.trailers.name" type="text">
<button (click)="back.createTruckAuth();back.createTrailAuth();back.createItemAuth();back.createItem()">create truck</button>
<p *ngFor="let car of carsData" status="success" class="col-sm-4">{{car.name}}></p>
如何在数据库中创建子项,以便我可以发布信息?