6

I'm trying to use the the new angular syntax for the old *ngIf. In my template I would like to combine the following to @if statements

@if(foo.bar$ | async;as bar) {
     <h2>{{bar}}</h2>
}

and

@if((foo.bar$ | async) !== 'yolo') {
    
}

Those work. Ideally I would like to combine them, something like

@if(foo.bar$ | async;as bar !== 'yolo') {
    <h2>{{bar}}</h2>
}

or

@if((foo.bar$ | async;as bar) && bar !== 'yolo') {
    <h2>{{bar}}</h2>
}

I can try more, but the point is, this is incorrect syntax. So my question is, is something like this possible or should I just have 2 @if statements?

2
  • 1
    Perhaps this post can help you. It's related to the old syntax, but I think it still applies to the new syntax stackoverflow.com/questions/49296784/… Commented Dec 12, 2023 at 14:50
  • 1
    Yes, that seems to work as: (foo.bar$ | async) !== 'yolo' && (foo.bar$ | async); as bar. Its using async twice, not ideal, but if this is it, this is it :) Thnx!! Commented Dec 12, 2023 at 15:11

1 Answer 1

3

Can upgrade to v18.2 and use

@let bar = foo.bar$ | async

And use it in throughout the template without having multiple subscriptions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.