Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Neither component in an ngIf statement are being shown even though one of them should be truey

I’m trying to use an ngIf to hide the details of a component until the required variable has been set. While it’s waiting it’s supposed to show a loading message. I’ve tried googling for the answer and have come up blank.

The code for the component

export class PrintBookingComponent implements  AfterContentInit {
  private Interface: MSLZohoInterface | undefined;

  constructor(private changeDetector: ChangeDetectorRef) {
  }
  ngAfterContentInit(): void {
    console.log("Initialising Print Booking");
    this.Interface = new MSLZohoInterface();
    var val = this.Interface.LoadBooking("4032446000000880091");
    if (val != undefined) {
      this.Booking = val;
      this.SelectedDate = this.Booking.Dates[0];
      //console.log(this.Booking);
    } else {
      this.Booking = <Booking>{};
    }
    this.HasBooking = true;
    //this.changeDetector.detectChanges();
  }
  Booking: Booking | undefined;
  HasBooking: boolean = false;
  SelectedDate: PrintDate | undefined;

}

The HTML for the component

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<ng-template *ngIf="Booking;">
  <H1>{{Booking.PrintBooking.Sales_Order.display_value}}</H1>
  <h2>{{Booking.PrintBooking.Account.display_value}} - {{Booking.PrintBooking.ContactID.display_value}}</h2>

  <div class="card-container" *ngFor="let d of Booking.Dates">
    <Button class="card-small" (click)="SelectedDate=(d)">
      {{d.publication}} - {{d.pubdate}}
    </Button>
  </div>
</ng-template>
<h1 *ngIf="!Booking;">Loading</h1>
<p>Print Component</p>

As you can see the code should be showing one or the other item, however when run it with ng serve I get this.
Screen shot of screen output showing the text Print Component

Can anyone see what I’m doing wrong?

>Solution :

Do you really mean

<ng-template *ngIf="Booking;">

and not

<ng-container *ngIf="Booking;">

?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading