-
Notifications
You must be signed in to change notification settings - Fork 3k
0.2.8 breaks ng-init in combination with ng-hide and ui-view #834
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
Comments
Awesome, thanks for the detailed write-up. I'll try to get on this later tonight. |
Use the linking function element instead of the template element when setting the parent.
@meenie thanks. if you believe your comments will cause confusion for this issue please delete them. |
I am having similar issue. I think this is related: http://stackoverflow.com/questions/21308563/add-a-class-to-the-ui-view-based-on-the-current-state It looks like that when other expressions are used in the same tag that uses ui-view directive makes these expressions interpreted with previous scope, or no scope if it is the first time. I think this is duplicate of #866 |
@damienklinnert - This issue is fixed with #858 PR. Once more testing is done (particularly with IE), it should become 0.2.9 pretty soon. |
@meenie awesome - thank you! |
Great! Closing :). |
First of all: Thank you for this great project, which gave me the power to create a perfect architecture for our huge angular app!
When upgrading ui-router to
0.2.8
, my angular1.2.10
app only renders blank pages.I invested several hours but wasn't able to find the cause of the problem. I hope you are able to resolve the problem. Thus, I added as much detail as possible.
Observation
My outmost
ui-view
directive is set up with anng-hide="isLoading"
and anng-init="isLoading = true"
. The proper state controller then setsisLoading=false
as soon as it is instantiated (after all values have been resolved).Here's a plunkr to reproduce the issue!
The blank page is caused by the outmost
ui-view
directive in the DOM, because it hasclass="ng-hide"
assigned to it - so the DOM is completely compiled, but hidden.After investigating further, I found out that the scope bound to the
ui-view
references the properscope.pageIsLoading
, which has a value offalse
. Also triggering$apply()
doesn't change anything.I'd expect the
class="ng-hide"
to have been disappeared now, but this is not the case. I tripple-checked the scope values and bindings and everything seams ok, except for theclass="ng-hide"
.This problem only appears when
ng-init
is used to setpageIsLoading = true
and when theng-hide
appears directly on theui-view
tag.Using
$scope
instead of$rootScope
in the controller doesn't resolve the problem.Removing the
ng-init
resolves the problem, but also removes my ability to show loading spinners.Wrapping the
ui-view
in a div and putting theng-hide
on it also resolves the problem, but adds additional DOM elements.Example:
Using
git bisect
I was able to track the problem to the filesrc/viewDirective.js
at the specific commita402415a2a28b360c43b9fe8f4f54c540f6c33de
by Nate Abele, which is a larger refactoring and changed a lot of things. Commits previously to this one worked fine.I compared both versions a lot, especially by stepping through them using the Chrome debugger. Here are my ideas and what I could find out:
What might cause the problem
In
src/viewDirective.js
lines121 - 170
, functionupdateView()
, something interesting is happening to the varselement
andcurrentScope
. The function is triggered twice when loading the page once.At the first time, the
if (isDefault)
andif (!locals)
branches are executed. The second time, both are skipped and the last part of the function is executed.When the function is invoked the second time and you stop directly at the first line, you can notice that the
element
references a$jqLite
selector that containsui-view.ng-hide
. This element is later cloned and compiled, maybe that's the reason for theng-hide
to stick around.With the working version, this is not the case.
What doesn't cause the problem, but looks awkward
Comparing Scope Trees
One thing I noticed is that the scope tree for nested
ui-view
s looks like this in previous commits:In later commits, it looks like this:
Although I think that it looks a little bit awkward (scope 003 is missing), ui-view always has a scope of 002 - it seams not to be related to the problem.
The text was updated successfully, but these errors were encountered: