user1405338
user1405338

Reputation: 189

Got interpolation ({{}}) where expression was expected with angular

I get error on my code with angular 6

<span *ngFor="let tag of item.payload.doc.data().TAGS" > 
                    <button class="nav-link active" (click)="searchByTags('{{tag}}')" >{{tag}},</button>
                </span>

I want to have dynamic {{tag}} into searchByTags function but it gives me next error:

Parser Error: Got interpolation ({{}}) where expression was expected at column 14 in [searchByTags('{{tag}}')] in ng:///AppModule/HomeComponent.html@76:56 ("et tag of item.payload.doc.data().TAGS" > 
                    <button class="nav-link active" [ERROR ->](click)="searchByTags('{{tag}}')" >{{tag}},</button>
                </span>

Upvotes: 1

Views: 3738

Answers (1)

Mathyn
Mathyn

Reputation: 2600

Change your code to this:

<span *ngFor="let tag of item.payload.doc.data().TAGS" > 
    <button class="nav-link active" (click)="searchByTags(tag)" >{{tag}},</button>
</span>

You do not need to interpolate the tag value inside the click handler. You can directly pass the value without interpolation.

Upvotes: 2

Related Questions