Skip to content

Proposal: Allow computed property names in map expressions #13855

Closed

Description

@santialbo

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
The expression parser currently doesn't support ES2015 computed property names, which allow to put an expression between brackets [] that will be computed as the property name.

Example of what's not currently supported:

<div [ngClass]="{[className1]: true, [className2]: foo()}"></div>

className1 and className2 are properties in the controller that contain the actual class names.

This can be overcome by creating a property/function in the component class.

get myClasses() {
  let self = this;
  return {
    [self.className1]: true,
    [self.className2]: self.foo()
  };
}
<div [ngClass]="myClasses"></div>

Expected behavior
First example to work.

What is the motivation / use case for changing the behavior?
This would avoid the need for creating such properties in the component.

Please tell us about your environment:

  • Angular version: 2.3.1

Activity

  1. changed the title [-]Proposal: Allow computed property name in map expressions[/-] [+]Proposal: Allow computed property names in map expressions[/+] on Jan 10, 2017
  2. santialbo commented on Jan 10, 2017

    @santialbo
    Author

    I've done some work as an exercise trying to add this feature. If it's ok I'd like to make a PR for discussing my changes.
    https://github.com/santialbo/angular/commit/37b311e10957d712b182f9de38ccec9fb187d3b0

    Regards

  3. DzmitryShylovich commented on Jan 16, 2017

    @DzmitryShylovich
    Contributor

    @santialbo open a pr

  4. added
    featureLabel used to distinguish feature request from other issues
    on Apr 10, 2017
  5. added this to the Backlog milestone on Jan 23, 2018
  6. 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.

  7. 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.

  8. added
    area: compilerIssues related to `ngc`, Angular's template compiler
    and removed
    area: coreIssues related to the framework runtime
    on Oct 6, 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

    I'm going to close this issue - but that's not a sign that we're not thinking about this.

    As Pete mentioned, this is something we think about more holistically - how Angular's expression syntax differs from JavaScript. We're unlikely to implement this as a particular feature (especially given the lack of upvotes) but as we work to align our expression syntax, it will come up again for discussion.

  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

No one assigned

    Labels

    area: compilerIssues related to `ngc`, Angular's template compilercompiler: parsercore: 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