Skip to content

feat(compiler): [property]="{{foo}}" should raise an exception #3645

Closed

Description

@jeffbcross

Some users during a hack night were trying to set properties this way. Since {{foo}} would never be a valid expression, the compiler should raise a helpful exception when this pattern is found. Since this pattern is predictable, the exception should give specific feedback.

My suggestion: {{foo}} is not a valid expression in [prop]="{{foo}}". Try [prop]="foo"

CC: @mhevery

Related: #3662 (should be done together)

Activity

  1. pkozlowski-opensource commented on Aug 15, 2015

    @pkozlowski-opensource
    Member

    So, today we are getting those errors for the <div [a]="{{b}}"> case:

    Parser Error: Unexpected token {, expected identifier, keyword, or string at column 2 in [{{b}}] in someComponent

    As for giving specific feedback: if we decide to go down this path we need to take all the binding forms (bind-a, data-bind-a) into account. Same goes for events ((click)="{{foo()}}") as well, I guess.

  2. 0x-r4bbit commented on Aug 15, 2015

    @0x-r4bbit
    Contributor

    I'm also voting for more specific error messages here, if it's not to
    expensive to implement. I think one thing that a lot of ppl struggled with
    in AngularJS, was that the error messages weren't super clear at a first
    glance (even tho I think minError is great). So if we can improve here, we
    should definitely do so

    On Sat, Aug 15, 2015, 11:26 AM Pawel Kozlowski [email protected]
    wrote:

    So, today we are getting those errors for the <div [a]="{{b}}"> case:

    Parser Error: Unexpected token {, expected identifier, keyword, or string
    at column 2 in [{{b}}] in someComponent

    As for giving specific feedback: if we decide to go down this path we need
    to take all the binding forms (bind-a, data-bind-a) into account. Same
    goes for events ((click)="{{foo()}}") as well, I guess.

    —
    Reply to this email directly or view it on GitHub
    #3645 (comment).

  3. mhevery commented on Aug 19, 2015

    @mhevery
    Contributor

    I think this should be implemented in the parser, and the error should read: Got interpolation '{{}}' when expression was expected. This can easily be done in Parser to see if the parsing text (expression) starts with {{

  4. pkozlowski-opensource commented on Aug 19, 2015

    @pkozlowski-opensource
    Member

    This can easily be done in Parser to see if the parsing text (expression) starts with {{

    We should probably also check for interpolations inside an expression string to catch cases like [foo]="before {{exp}} after"

  5. added a commit that references this issue on Aug 21, 2015
    9675fd4
  6. angular-automatic-lock-bot commented on Sep 7, 2019

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

  7. locked and limited conversation to collaborators on Sep 7, 2019
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

    effort1: hoursfeatureLabel used to distinguish feature request from other issuesopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions