1.13.9. fejezet, Signal

Kapcsolódó hivatkozások

app.component.ts

  width = signal(10)
  height = signal(20)
  area = computed(() => this.width() * this.height())
  constructor() {  
    effect(() => {
       console.log("Effect due to width signal is triggered.", this.width())
    })
    effect(() => {
       console.log("Effect due to height signal is triggered.", this.height())
    })
  }
 
  incHeight() {
    this.height.update(() => this.height() * 2)
  }
 
  incWidth() {
    this.width.update(() => this.width() * 2)
  }

app.component.html

<p-button (onClick)="incWidth()">incWidth</p-button>
<p-button (onClick)="incHeight()">incHeight</p-button>
<br/><br/>
{{area()}}