import { CommonModule } from '@angular/common'; import { AfterViewInit, ChangeDetectionStrategy, Component, OnInit, forwardRef, input, model, } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { ListMessage } from '../model/proto-message.model'; import { ProtoFieldComponent } from '../proto-field/proto-field.component'; @Component({ selector: 'app-list-field', standalone: true, imports: [ CommonModule, MatButtonModule, MatIconModule, forwardRef(() => ProtoFieldComponent), ], template: `

{{ label() }}

@if(values()) { @for(value of values(); track $index) {
} } `, styleUrl: './list-field.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, }) export class ListFieldComponent { label = input(); configuration = input.required(); values = model(); add() { const existingValues = this.values(); if (existingValues) { const newValues = [...existingValues]; newValues.push(undefined); this.values.set(newValues); } else { this.values.set([undefined]); } } remove(index: number) { const newValues = [...this.values()!]; newValues.splice(index, 1); this.values.set(newValues); } updateValue(index: number, value: any) { let existing = [...this.values()!]; existing[index] = value; this.values.set(existing); } }