Sebastian
Sebastian

Reputation: 45

How to get specific value in Array of objects in typescript

I have an Array of objects which I loop through with *ngfor and display in a ngdropdownmenu. I select one and return one of the objects which contain a name and an action and assign it to a string variable. How can I only get action value of selected object in typescript?

//Typescript Code:
specificaction: string = "";
public finishActions = [
{ name: "blah", action: "blahblahblah" },
{ name: "blah", action: "blahblahblah" },
{ name: "blah", action: "blahblahblah" },
{ name: "blah", action: "blahblahblah" },
{ name: "blah", action: "blahblahblah" },
{ name: "", action: "" }
] 
finishAction(action: string) {
this.specificaction= action;
//I CAN NOT GET THE specification.action
console.log(this.specificaction.action);
 }

//HTML
<div ngbDropdownMenu aria-labelledby="dropdownBasic1">
  <button class="dropdown-item text-right" *ngFor="let action of 
finishActions" (click)="finishAction(action)">{{action.name}}</button>
</div>

Upvotes: 1

Views: 851

Answers (1)

Leo
Leo

Reputation: 751

I would do something like this:

<div *ngFor="let finishAction of finishActions">
    <p>{{ finishAction.action }}</p>
</div>

Upvotes: 1

Related Questions