我有一个对象数组,我用* ngfor循环并在ngdropdownmenu中显示。我选择一个并返回一个包含名称和操作的对象,并将其分配给字符串变量。 我怎样才能在打字稿中获取所选对象的动作值?
//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>
答案 0 :(得分:1)
我会做这样的事情:
<div *ngFor="let finishAction of finishActions">
<p>{{ finishAction.action }}</p>
</div>