import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
MultiSelectChangeEventDetail,
type PMultiSelectProps,
PorscheDesignSystemModule,
} from '@porsche-design-system/components-angular';
@Component({
selector: 'porsche-design-system-app',
template: `
@for (idx of optionIndices; track idx) {
Option {{ idx + 1 }}
}
Add option
Remove last option
`,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [PorscheDesignSystemModule],
})
export class ExampleComponent {
selectedValues: PMultiSelectProps['value'] = [];
inputValue: string = '';
optionCount: number = 3;
get optionIndices(): number[] {
return [...Array(this.optionCount).keys()];
}
onChangeInput(e: Event) {
this.inputValue = (e.target as HTMLInputElement).value;
}
onSetValue() {
this.selectedValues = this.inputValue.split(',');
}
onResetValue() {
this.selectedValues = [];
this.inputValue = '';
}
onChange(e: CustomEvent) {
this.selectedValues = e.detail.value;
this.inputValue = e.detail.value.join(',');
}
onAddOption() {
this.optionCount += 1;
}
onRemoveOption() {
if (this.optionCount > 0) {
this.optionCount -= 1;
}
}
}