* ngIf check if attribute exists

I am using angular2 and I want to make a condition to display something

For example, if it will be displayed group.permisions=Can Create File something.

This is my code.

<div class="col-md-9" *ngIf="t?.groups[0].id===Can Create File">
     <p class="form-control-static">Can check File</p>
</div>

But I got an error Parser Error: Missing expected ). I do not understand where my problem is.

+4
source share
2 answers

You misisng quote , ''

<div class="col-md-9" *ngIf="t?.groups[0].id==='Can Create File'">
+5
source

if your identifier is a string type and you want to compare with the string:

<div class="col-md-9" *ngIf="t?.groups[0]?.id === 'Can Create File'">
     <p class="form-control-static">Can check File</p>
</div>
0
source

Source: https://habr.com/ru/post/1674625/


All Articles