What is the best way to @output
the value of a variable with angular signal ?
Let say we have the following
$foo = signal<string>('')
@Output() fooChanged: EventEmitter<string> = new EventEmitter<string(this.$foo())
effect: My first though would have been to use
effect
but as I read it, it should kind of being avoided if possible.computed: I would love to use it, but I don't know how to implement it properly
What is the best way to @output
the value of a variable with angular signal ?
Let say we have the following
$foo = signal<string>('')
@Output() fooChanged: EventEmitter<string> = new EventEmitter<string(this.$foo())
effect: My first though would have been to use
effect
but as I read it, it should kind of being avoided if possible.computed: I would love to use it, but I don't know how to implement it properly
1 Answer
Reset to default 1Looks like you want to do two way data binding, then just use a model
signal.
@Component({ selector:'test' ... })
export class Test component {
$foo = model<string>('');
}
Now you can use this in two ways.
Directly bind the property using two way data binding.
<test [($foo)]="fooParent"></test>
Or if you want to call an event you can use the change suffix syntax like so
<test [$foo]="fooParent" ($fooChange)="fooChangeEvent($event)"></test>
countryChanged
when the$selectedCountry
have changed. If I understand correctlyeffect
is the way to go, and angular does not have a better way to go ? : github/rbalet/ngx-mat-input-tel/blob/main/projects/… – Raphaël Balet Commented Mar 9 at 14:11