Reputation: 385
I have a list of items stored in an array named "permissions" and the data is like this
When i click on the particular item i want only the particular items data to be displayed.
component.html
<a class="selected" (click)="displayPermission()">click</a>
component.ts
displayPermission(){
//what will be the logic inside here;
console.log(logic needed);
}
Upvotes: 0
Views: 1827
Reputation: 522
component.html
<ng-container *ngFor="let item of permissions">
<a class="selected" (click)="displayPermission(item)">click</a>
<ng-container *ngIf="item.open">
<!-- html for item details -->
<p>{{item.group_id}}<p>
</ng-container>
</ng-container>
component.ts
displayPermission(item){
item.open = !item.open;
}
Upvotes: 1
Reputation: 2312
You can display the data in .html using *ngFor
directive which will iterate over your list of items on whose click you can call a function with the index
of that particular item in array.
.component.html
permissions = [{},{},{}]
showData(index){
// Do anything with the selected item
console.log(permissions[index]);
}
.component.html
<div *ngFor="let p of permissions;let i = index">
<button (click)="showData(i)">Permission {{i}}</button>
</div>
Upvotes: 1
Reputation: 24424
try this
template
<div *ngFor="let item of items">
<a class="selected" (click)="displayPermission(item)">click</a>
</div>
componenet
displayPermission(data){
consolelog(data);
console.log(logic needed);
}
Upvotes: 1