我正在对来自某些数据库的数据进行反规范化,以避免联接查询,因此,当我要在“ Pedido”集合中注册某些内容时,我会将“ Usuario”(已登录)的数据放入其中,所选“客户”的数据。我将以离子选择的方式显示整个“客户”集合,因此我可以选择它并继续进行操作,但是如何从中获取唯一的选定文档呢?另外,由于出现错误,我只能选择“ Cliente”集合的第一个值,离子选择不会让我选择另一个。
private formCriarPedido: FormGroup;
private clientesCollection: AngularFirestoreCollection<Cliente>;
private clientes$: Observable<Cliente[]>;
constructor(
private fb: FormBuilder,
public auth: AuthService,
private toast: ToastService,
private db: AngularFirestore
) {
this.formCriarPedido = this.fb.group({
clientePedido: ['', Validators.compose([Validators.required])],
});
this.clientesCollection = this.db.collection<Cliente>('cliente');
this.clientes$ = this.clientesCollection.valueChanges();
}
ngOnInit() {
}
iniciarPedido() {
}
escolheCliente(cliente: Cliente) {
console.log(cliente);
}
<ion-label position="stacked">Cliente</ion-label>
<ion-select class="selectCliente" (ionChange)="escolheCliente($event)" formControlName="clientePedido">
<ion-select-option value="{{cliente}}" *ngFor="let cliente of clientes$ | async">{{cliente.razaoSocialCliente}}</ion-select-option>
</ion-select>
<div align-self-start ngxErrors="clientePedido">
<div [ngxError]="['required']" [when]="['touched']">
<p class="alert-validation">
É necessário selecionar o Cliente!
</p>
</div>
</div>
</ion-item>
答案 0 :(得分:0)
迅速发现错误,似乎是离子4变化。为了使这项工作正常进行,您应该更改以下行:
<ion-select-option value="{{cliente}}" *ngFor="let cliente of clientes$ | async">{{cliente.razaoSocialCliente}}</ion-select-option>
收件人:
<ion-select-option [value]="cliente" *ngFor="let cliente of clientes$ | async">{{cliente.razaoSocialCliente}}</ion-select-option>
在https://stackoverflow.com/users/11216133/othmane-daanouni的Pass ion-select-option to function - Ionic 4点数