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

bread crum label doesn't update when the $scope is updated #20

Closed
mastilver opened this issue Jun 13, 2014 · 6 comments
Closed

bread crum label doesn't update when the $scope is updated #20

mastilver opened this issue Jun 13, 2014 · 6 comments
Labels

Comments

@mastilver
Copy link
Contributor

see this Plunker: http://plnkr.co/edit/BN0M2vvZccDq1KOKsSfC

Btw: awesome module! :)

@mastilver
Copy link
Contributor Author

My boss and I did a bit of research.

Maybe you shouldn't use $interpolate in the directive but $sce (dependency of $interpolate).
You should take a look at that: http://devdocs.io/angular/ng.$sce (the ngBindHtml directive part may be interesting)

@ncuillery
Copy link
Owner

Right, thanks for reporting (and investigating :) )

Maybe I'm wrong but $sce only deals with safe HTML inclusion (I already worked on it: #18). It won't help us here because the breadcrumb construction is based on the $viewContentLoaded event. When the scope is updated, no event is fired so the breadcrumb doesn't update.

As a first approach, I see 2 solutions:

  • A custom event (like ncyBreadcrumb:update) listened by the directive which the developer has to $emit
  • Add a watcher on each labels in the breadcrumb: no overhead for the developer but probably performance implications.

Work in progress ;)

@ncuillery
Copy link
Owner

Pending the fix, here is a quick workaround:

Just after the scope update, add the line

$scope.$new().$emit('$viewContentLoaded');

See http://plnkr.co/edit/vpr1bWK85sxaHncJ3uZG?p=preview

@mastilver
Copy link
Contributor Author

Thank you!
I didn't think about that...
But i don't see the point of creating a new scope to emit the event. (As we can emit it from the current scope)

@ncuillery
Copy link
Owner

When a nested view is accessed by direct URL, several $viewContentLoaded are emited (one for each level of nesting). But the angular event system is not totally reliable: the directive sometime received the events in the wrong order, making the breadcrumb generating on an intermediate state (and so was incomplete).

To avoid this (#10), I use the $id of the scope which emit the event. It's a counter increasing after each scope creation. The deepest nested view has a scope with the greatest $id (i.e. the lastly created). So I generate the breadcrumb only if the scope has a greater $id than the one in the previous $viewContentLoaded.

In your case, the scope has already emit a $viewContentLoaded and a second one would be ignored. By created a new scope, I'm sure the event will be processed (new $id)

It's clearly a workaround, not a fix :)

@ncuillery ncuillery added the bug label Jun 15, 2014
mastilver pushed a commit to mastilver/angular-breadcrumb that referenced this issue Jun 23, 2014
@ncuillery
Copy link
Owner

1363515

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants