Ng-if id != null


I need to show an element only if the user is logged in (which means that the user should have an id stored in his device)
here is my html component :

ion-card-title ng-if="id != null">write a review</ion-card-title>
        <form [formGroup]="reviewForm" (submit)="writeReview($event)">

              <ion-input type="text" formControlName="name" placeholder="name"></ion-input>
              <ion-input type="text" formControlName="review" placeholder="review"></ion-input>
  <ion-select formControlName="rate">
    <ion-option value="5">5</ion-option>
    <ion-option value="4">4</ion-option>
    <ion-option value="3">3</ion-option>
    <ion-option value="2">2</ion-option>
    <ion-option value="1">1</ion-option>
          <button ion-button color="secondary" block type="submit" >add your review</button><br />

Best approach to design an UI for creating users and assigning them to a level

ng-if is Angular 1 syntax, so you want *ngIf instead. JavaScript’s notion of null and undefined and so on is so baroque that I recommend steering well clear of it and would do *ngIf="!!id" instead.


@keloa Hi Keloa, in terms of app design, I wonder why you check if the user is authenticated only at this stage in your code (template view)?

Can’t you check before in the .ts file or better the provider, if your user is granted permission? Not to mention, it will be easier to debug and lighten page processing.


This seems like a perfectly reasonable design to me. You show the same page to guests and authenticated users, only certain features are omitted in the guest case.


Alright if this view is open both to guests and registered users.


I want the guests to be able to see the reviews whereas the users can see and write the reviews , (to limit the spammers and it is useful in some future updates)