Я должен поднять отношение для x*2 = y < /code>, есть y и y поля ввода.import { Component, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-root',
imports: [FormsModule],
template: `
{{ title }}
*2 =
`,
})
export class App {
protected title = 'Relationshiphandling: 2*X=Y'
X=signal(0);
Y=signal(0);
FnX() {
this.Y.set(2 * this.X());
};
FnY() {
this.X.set(this.Y() / 2);
};
}
< /code>
Теперь вопрос: возможно ли решить такие циклы с помощью LinkedSignal < /strong>?X: WritableSignal = linkedSignal({
source: () => this.Y(),
computation: (_source: number, _prev?: { source: number; value: number }) => {
const newValue = _source / 2;
**if (this.X() == newValue) { return 0};** // Do nothing if the same value
console.log( "this.X.set(newValue)")
this.X.set(newValue);
return newValue;
}
});
Y: WritableSignal = linkedSignal({
source: () => this.X(),
computation: (_source: number, _prev?: { source: number; value: number }) => {
const newValue = _source * 2;
**if (this.Y() == newValue) { return 0};** // Do nothing if the same value
this.Y.set(newValue)
console.log( "this.Y.set(newValue)")
return newValue;
}
});
Подробнее здесь: https://stackoverflow.com/questions/796 ... ngular-v20
Как вручить отношения между двумя сигналами с помощью LinkedSignals в Angular V20? ⇐ Html
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Создание отмены/восстановления с помощью команды PySide6 с сигналами блока
Anonymous » » в форуме Python - 0 Ответы
- 19 Просмотры
-
Последнее сообщение Anonymous
-