I try to use a PrimeNG SplitButton.
@Component({
selector: 'test',
template: `
<ul>
<li *ngFor="let l of lst">{{ l }}
<p-splitButton label="foo" (onClick)="foo (l)" [model]="menu"></p-splitButton>
</li>
</ul>
`
})
export class TestComponent
{
lst : string [] = ["abc", "123", "xyz"];
menu : MenuItem [] = [{label: "bar", command: (e) => { this.bar (e) }}];
foo (x)
{
console.log ("foo", x);
}
bar (x)
{
console.log ("bar", x);
}
}
How can I pass the value of the iteration of lst (l) to bar? I want use it the same way as I do it with foo but not sure how to get the argument down to menu.
You can use the
onDropdownClickevent to store the index of the splitButton you're currently opening and then use it inside bar, like this: