p-checkbox does not maintaining it's Checked value if I clicked on another component and come...

Discussão em 'Angular' iniciado por Steff, Outubro 24, 2024.

  1. Steff

    Steff Guest

    I am using AngularTS with primeNG.
    below is my code for html p-checkbox, as well I have the rowEdit on row Click feature with extra this code, so when I am doing edit modal and come back this this.

    selectDeleteTaskNode code has the selected node but checkbox is not showing checked.[checked == true]


    <p-checkbox
    *ngIf="i === 0"
    [binary]="true"
    class="mr-1"
    styleClass="edit-checkbox"
    [disabled]="!canEdit"
    (onChange)="onCheckboxChange($event, rowNode)"
    (click)="$event.stopPropagation()"
    ></p-checkbox>


    below is my TS code for the above

    onCheckboxChange(event: any, rowNode: any) {
    if (event.checked === true) {
    this.selectDeleteTaskNode.push(rowNode.node);
    // Update the node selection state
    this.nodeSelectionStates[rowNode.node] = event.checked;
    } else {
    const index = this.selectDeleteTaskNode.indexOf(rowNode.node);
    if (index > -1) {
    this.selectDeleteTaskNode.splice(index, 1);
    this.nodeSelectionStates[rowNode.node] = !event.checked;
    }
    }
    }


    if I can filter that [(ngModal)] value by some condition it will check wether the node is present inside

    selectDeleteTaskNode or not if yes then p-checkbox's checked ==true else False

    Continue reading...

Compartilhe esta Página