Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router. EXCEPTION: Expression has changed after it was checked. #6006

Closed
nglazov opened this issue Dec 18, 2015 · 7 comments
Closed

Router. EXCEPTION: Expression has changed after it was checked. #6006

nglazov opened this issue Dec 18, 2015 · 7 comments

Comments

@nglazov
Copy link

nglazov commented Dec 18, 2015

I use [routerLink]="someFunction('Route')"

someFunction(a) {
  return [a]
}

This is example which was taked from docs and was changed just app/app.component.ts.

@wardbell
Copy link
Contributor

While you have definitely found a problem and I believe that what you're trying to do ought to work ... and we're looking into it ... I can't find that example you cite anywhere in the docs. Would you please find that location for me?

@wardbell
Copy link
Contributor

Anyway, the reason you're getting this error now is because, in DevMode (which is the default), Angular runs your fn 2x ... once the normal time, and once again during a check to ensure that you aren't changing things that shouldn't change during the same view-generation pass.

Semantically, you're not changing anything. You're specifying the same route [a] each time.

But technically you're returning a **different array* each time.

The solution (for now) is to run your fn inside your component, capture its value in a component property, and bind to that property instead.

Here's some pseudo-code:

<!-- Template HTML -->
...[RouterLink]="theRoute" ...

// Component
theRoute: RouterLink;
...
theRoute = someFunction(whatever);

@nglazov
Copy link
Author

nglazov commented Dec 18, 2015

I mean live example from docs.
Yes, i've tried this before and function will be called 10 times (example).

@wardbell
Copy link
Contributor

I searched the code and couldn't find [routerLink]="getLink()". I think I understand the problem. I think you have an old plunker from an earlier version of the doc. If you click the live example link now, you'll get a different result.

The problem is real. But it's not in the router doc. I think we should close this one.

@nglazov
Copy link
Author

nglazov commented Dec 19, 2015

Oh yeah, it's not from doc. I've forked example and have changed it.
The problem is to use function as input parameter in routerLink directive.

@pkozlowski-opensource
Copy link
Member

Same as #6005

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants