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

Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

angular expression assignment bug #3869

Closed
lgersman opened this issue Sep 4, 2013 · 4 comments
Closed

angular expression assignment bug #3869

lgersman opened this issue Sep 4, 2013 · 4 comments

Comments

@lgersman
Copy link

lgersman commented Sep 4, 2013

hi,

i just recognized that angular expression assignments with filter seems to be buggy (tested in Angular 1.1.5).

When i do an assignment within an ng-init

ng-init="test1 = data | orderBy:'name'"

i just get just data without applied orderBy. the same without assignment

{{data | orderBy:'name'}}

works as expected (orderBy is applied).

I can workaround it by rewriting my ng-init assignment to

ng-init="test1 = (data | orderBy:'name')"

Testcase : http://jsfiddle.net/lgersman/kMcnU/

Kind regards,

Lars

@lgersman
Copy link
Author

... Am I the only one not in holidays ?

Or was the triggered issue perhaps stupid ( ... I don't believe it) ?

@et
Copy link

et commented Sep 27, 2013

I think this is because ng-init internally calls $eval which calls $parse which evaluates the pipe | as a bitwise OR operator.

This would probably be a question to the core team to decide what the correct implementation should be.

@rodyhaddad
Copy link
Contributor

@et the bitwise OR operator is commented out. | in angular expressions is for filters only.

This issue is not a bug, and this is why:

The problem is that = has a higher operator precedence than |, making the test1 = data | orderBy:'name' expression be executed as (test1 = data) | orderBy:'name'

IMHO, this is the expected behaviour: | (filters) has the lowest operator precedence in a statement, which makes sense, and is intentional.

So test1 = (data | orderBy:'name') is the way to go to accomplish what you're trying to do. Unless someone can make a better case for = to have a lower operator precedence than | .

@et
Copy link

et commented Sep 27, 2013

@rodyhaddad - good call. I agree with the expected behavior.

Is there a place in the docs that mention the precedence?

clkao added a commit to clkao/angular.js that referenced this issue Jan 18, 2014
@caitp caitp closed this as completed in 42ec95e Jan 18, 2014
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Clears up expression priority issue

Closes angular#3869
Closes angular#5873
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Clears up expression priority issue

Closes angular#3869
Closes angular#5873
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants