Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Control Flow @if: alway call pipe even if the previous condition is false #62076

Closed as not planned
@cesco69

Description

@cesco69

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

Angular always call the pipe even if the previous condition is false in a @if, eg:

@if(false && value() | test){}

In this case, because the first condition is false, se second condition can be skipped

full example

import { Component, Pipe, PipeTransform, signal } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';

@Pipe({
  name: 'test',
})
export class TestPipe implements PipeTransform {
  transform(value: any): boolean {
    console.log('TestPipe');
    return value;
  }
}

@Component({
  selector: 'app-root',
  template: `
    @if(condition() && value() | test){
      true
    } @else {
      false
    }
  `,
  imports: [TestPipe],
})
export class App {
  condition = signal(false);
  value = signal(null);
}

bootstrapApplication(App);

console show:

TestPipe

expected nothing

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-zmyb1dnl

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)


Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions