-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
Which @angular/* package(s) are relevant/related to the feature request?
compiler
Description
I'm interested in hearing opinions on allowing the use of the instanceof operator within the @if control block. Sometimes, I want to expose a template based on the instance of an object rather than its properties.
While Angular templates is designed with a declarative UI composition in mind, I wonder if instanceof might not be considered declarative enough. If there is any reason for not considering it, could it be related to performance or debugging concerns?
Example:
@if(myObject instanceof SomeClass) {
<!-- This template will only be displayed if myObject is an instance of SomeClass -->
<div class='some'>
Content for SomeClass instance.
</div>
}Proposed solution
Here is a stackblitz
Alternatives considered
Pre-Computed Properties: Compute the instanceof result in the component and bind it to the template.
Custom Pipe: Use a custom pipe to encapsulate the instanceof logic.
Custom Structural Directive: Create a directive to handle the instanceof check declaratively.