如何从集合中获取一个文档,并使用 ion-select 列出所有文档?

How can I get one doc from a collection, with ion-select listing all the docs?

我正在对来自某些数据库的数据进行非规范化,以避免连接查询,所以当我要在 'Pedido' 集合中注册某些内容时,我将 'Usuario' 的数据(这是已登录),以及 selected 'Cliente' 的数据。我将在 ion-select 中显示整个 'Cliente' 集合,因此我可以选择它并继续,但如何从中获取唯一的 selected 文档?另外,作为额外的错误,我只能 select 'Cliente' 集合的第一个值,ion-select 不会让我选择另一个。

      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>

很快就发现了错误,好像是ionic 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://whosebug.com/users/11216133/othmane-daanouni at