Skip to content

feat(compiler): Support "in" operator in Angular templates #38560

Closed

Description

@manueledones

🚀 feature request

Description

I'd like to have your opinions about supporting "in" operator in html templates. Let's say I have an object of a union type A | B. I'd like to use the 'in' operator to differentiate type.
Something like:

export interface A {
  a: number
}

export interface B {
  b: string
}

export type MyUnionType = A | B;

item: MyUnionType = {
    a: 1
  }

<div *ngIf="'a' in item">
  I'm expecting item is no longer of type A | B, but only A
  {{item.a}}
</div>

Here is a stackblitz

Activity

  1. changed the title [-]Support "in" operator in Angular teplate[/-] [+]Support "in" operator in Angular templates[/+] on Aug 24, 2020
  2. added
    area: compilerIssues related to `ngc`, Angular's template compiler
    area: coreIssues related to the framework runtime
    on Aug 24, 2020
  3. modified the milestone: Backlog on Aug 24, 2020
  4. angular-robot commented on Jun 4, 2021

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  5. angular-robot commented on Jun 24, 2021

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  6. alxhub commented on Jul 8, 2021

    @alxhub
    Member

    In this spirit of aligning Angular expression syntax with JS expression syntax, I'm moving this into our triage process for further discussion.

  7. changed the title [-]Support "in" operator in Angular templates[/-] [+]feat(compikler): Support "in" operator in Angular templates[/+] on Sep 17, 2021
  8. changed the title [-]feat(compikler): Support "in" operator in Angular templates[/-] [+]feat(compiler): Support "in" operator in Angular templates[/+] on Sep 17, 2021
  9. petebacondarwin commented on Oct 15, 2021

    @petebacondarwin
    Contributor

    This is being tracked in the aggregate issue of #43485 for which we need to create a project proposal.

  10. alxhub commented on Feb 1, 2022

    @alxhub
    Member

    ^ closing as we're discussing these improvements to template expression syntax holistically, along the theme of unifying Angular syntax with JS.

  11. angular-automatic-lock-bot commented on Mar 4, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  12. locked and limited conversation to collaborators on Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: compilerIssues related to `ngc`, Angular's template compilerarea: coreIssues related to the framework runtimecore: binding & interpolationIssue related to property/attribute binding or text interpolationfeatureLabel used to distinguish feature request from other issues

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions