2

i started work with Neabular and i'm struggling with the documentation…

I've created a nebular popover with a form and i would like to close it when the form is validated and don't close it when the form is not validated. How can i do this ?

Here is the code :

<button [nbPopover]="addMenunItem" nbButton status="success">AJOUTER</button>
<ng-template #addMenunItem>
  <div class="p-4">
    <div class="w-100 pb-4">
      <h5>Créer un menu</h5>
    </div>

    <form [formGroup]="createMenuForm" (ngSubmit)="onSubmit()" novalidate>
      <div class="form-group">
        <input type="text" placeholder="Titre" formControlName="title" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.title.errors }">
        <div *ngIf="submitted && f.title.errors" class="invalid-feedback">
            <div *ngIf="f.title.errors.required">Le titre est obligatoire</div>
        </div>
      </div>
      <div class="form-group">
        <nb-checkbox id="private" class="private"></nb-checkbox>
        <label for="private">Privé</label>
      </div>
      <button type="submit" [disabled]="loading" class="btn btn-success w-100">Enregistrer</button>
    </form>
  </div>
</ng-template>
Vladimir Lugovsky
  • 197
  • 1
  • 4
  • 12
Mushu8
  • 173
  • 1
  • 13

2 Answers2

2

For one popover (source):

@ViewChild(NbPopoverDirective) popover;
[…]
this.popover.hide();

For multiple:

@ViewChildren(NbPopoverDirective) popovers: QueryList<NbPopoverDirective>;
[…]
this.popovers.forEach(pop => {
    pop.hide();
});
Goigle
  • 138
  • 13
0

Found it :

@ViewChild(NbPopoverDirective) popover;
[…]
this.popover.hide();

an interrogation remains : what if there are multiple popover in a component… ?

Mushu8
  • 173
  • 1
  • 13