1

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>
1
  • If you already have the object, just get its property like item.action. Commented Jun 15, 2018 at 15:36

1 Answer 1

1

I would do something like this:

<div *ngFor="let finishAction of finishActions">
    <p>{{ finishAction.action }}</p>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

I need the value of {{ finishAction.action }} to be saved in 'specificaction: string = "";'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.