File

libs/acl/angular/src/lib/policy-editor/edit-text/edit-text.component.ts

Implements

OnChanges

Metadata

Index

Properties
Methods
Inputs
Outputs

Inputs

value
Type : string | null
Default value : null

Outputs

update
Type : EventEmitter

Methods

handleDataUpdated
handleDataUpdated()
Returns : void

Properties

inputControl
Type : UntypedFormControl
Default value : new UntypedFormControl(null)
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { UntypedFormControl } from '@angular/forms';

@Component({
  // eslint-disable-next-line @angular-eslint/component-selector
  selector: 'edit-text',
  templateUrl: './edit-text.component.html',
  styleUrls: ['./edit-text.component.scss'],
  standalone: false
})
export class EditTextComponent implements OnChanges {
  @Input() value: string | null = null;
  @Output() update = new EventEmitter();
  inputControl: UntypedFormControl = new UntypedFormControl(null);

  handleDataUpdated() {
    const newValue = this.inputControl.value;
    if (newValue !== this.value) {
      this.update.emit(newValue);
    }
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (changes['value']) {
      this.inputControl.setValue(changes['value'].currentValue, { emitEvent: false });
    }
  }
}
<acl-editable (editComplete)="handleDataUpdated()">
  <ng-template aclViewMode>
    <span>{{ value || '-' }}</span>
  </ng-template>
  <ng-template aclEditMode>
    <input type="text" focusable [formControl]="inputControl" />
  </ng-template>
</acl-editable>

./edit-text.component.scss

@use '../../inspector.colors' as *;

:host {
  display: block;
  overflow: hidden;
}
input {
  background-color: $debug-color-dark;
  color: #fff;
  width: 100%;
  height: 24px;
  line-height: 18px;
  vertical-align: middle;
  outline: none;
  border: 1px solid $debug-color-light;
  padding: 1px 3px;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""