In angular I can use signals in templates like this (user is a signal):
<code>@if (user(); as user) { <!-- ✅ -->
<p>{{ user.name }}</p>
}
</code>
<code>@if (user(); as user) { <!-- ✅ -->
<p>{{ user.name }}</p>
}
</code>
@if (user(); as user) { <!-- ✅ -->
<p>{{ user.name }}</p>
}
Now I’m curious if the typescript also allows me to “check and assign” in one go too like this:
<code>if(this.myService.someFn(); as myReturnValue) { // ⛔
// do something with myReturnValue
}
</code>
<code>if(this.myService.someFn(); as myReturnValue) { // ⛔
// do something with myReturnValue
}
</code>
if(this.myService.someFn(); as myReturnValue) { // ⛔
// do something with myReturnValue
}
Is there a possiblity to do null-check and assign in one go within an if-condition?