import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
PInputText,
PorscheDesignSystemModule,
PSelect,
SelectChangeEventDetail,
} 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 {
selectedValue: PSelect['value'] = '1';
inputValue: PInputText['value'] = '';
optionCount: number = 3;
get optionIndices(): number[] {
return [...Array(this.optionCount).keys()];
}
onChangeInput(e: Event) {
this.inputValue = (e.target as HTMLInputElement).value;
}
onSetValue() {
this.selectedValue = this.inputValue;
}
onResetValue() {
this.selectedValue = '1';
this.inputValue = '';
}
onChange(e: CustomEvent) {
this.selectedValue = e.detail.value;
this.inputValue = String(e.detail.value ?? '');
}
onAddOption() {
this.optionCount += 1;
}
onRemoveOption() {
if (this.optionCount > 0) {
this.optionCount -= 1;
}
}
}