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

Branch angular-1.2 doesn't accept ui-view inside an ng-if #552

Closed
swallez opened this issue Nov 1, 2013 · 6 comments
Closed

Branch angular-1.2 doesn't accept ui-view inside an ng-if #552

swallez opened this issue Nov 1, 2013 · 6 comments

Comments

@swallez
Copy link

swallez commented Nov 1, 2013

I'm currently using ui-router 0.2.0 with Angular 1.2-rc3 and wanted to try the angular-1.2 branch to use the new animation stuff.

In this branch, the ui-view directive doesn't work if it's a child of an ng-if directive: the view can't find its parent and so its name is not correctly resolved.

I tracked this down to var parent = element.parent().inheritedData('$uiView') in viewDirective.js: when this code is called, the element is in a DOM document fragment created by the ng-if directive, and so the parent view can't be found.

I haven't been able to understand why with ui-router 0.2.0 the document fragment has already been inserted in the main DOM when we reach the equivalent code. Could this be related to the ui-view directive not having transclude: true in the angular-1.2 branch?

Here's a plunker showing the issue: http://plnkr.co/edit/l97kW2LCcpK2sOjFuoUS?p=preview - you can switch between 0.2.0 and the current angular-1.2 branch by changing the comments in index.html

@jonrimmer
Copy link

The problem is that the ui-view directive in the 1.2 branch performs the parent lookup on the compiled element, rather than the linked element, but the compiled element may no longer be in the DOM in cases like these.

I can submit a PR to fix this when the other 1.2 ui-view refactors have been applied. If you need some working code right away, check the following plunk:

http://plnkr.co/edit/go9Gvj5nFuDtDDZySYsv?p=preview

@swallez
Copy link
Author

swallez commented Nov 6, 2013

Wow, thanks a lot! I'll check this out!

In the meantime, I implemented a workaround : my use case is a stack of overlapping panels, and I want to hide those panels that are not active (i.e. have no template set). The ng-if was meant to remove inactive panels entirely from the DOM.

I solved this by adding a "hide-default" attribute to ui-view that prevents the insertion of the view element in the DOM if it has its default content. Works like a charm for me, and I'm wondering if this could be a useful addition to ui-router.

@wcandillon
Copy link

+1
Thank Jon!

sayeed-anjum added a commit to greytip/ui-router that referenced this issue Jan 3, 2014
meenie pushed a commit to meenie/ui-router that referenced this issue Mar 4, 2014
- Changed the structure of the uiView directive to work more like ngView.
- Updated tests to work with new structure.
- Fixes the issue with using ngIf in conjunction with uiView.
- Added in extensive test for ngIf fix.

Closes angular-ui#857, angular-ui#552
meenie pushed a commit to meenie/ui-router that referenced this issue Mar 6, 2014
 - Changed the structure of the uiView directive to work more like ngView.
 - Updated tests to work with new structure.
 - Updated tests so that all assertions actually run through AngularJS 1.0.8.
 - Added in extensive test for ngIf fix.
 - Added in ability for uiView to work with ngIf, ngRepeat, and ngClass.
 - Updated base AngularJS version to 1.2.14 to test $animate callbacks in 1.2.*
 - Fixes controllerAs so that it will work within a view declaration.

Closes angular-ui#857, angular-ui#552
@paulbhartzog
Copy link

ui-view still does not work inside of ng-if

@eddiemonge
Copy link
Contributor

Unfortunately, the issue tracker for this has gotten a bit out of control. In the interest of weeding out real bugs and feature requests, this issue is being closed. If you feel like the problem reported is still valid, please add a comment saying it is still affecting you. We will reevaluate it and if it is valid we will reopen it.

You can/should/please also try the new feature-1.0 branch that is in development to see if it fixes your issue. Keep in mind this is still in development but it is the direction the project is heading. If you want to file a ticket against this branch, use the format 1.0: (subject) for the subject.

You can also try asking on StackOverflow if this is an implementation issue rather than a bug in ui-router.

Thank you for supporting and contributing to the project.

@jlynchISM
Copy link

The key here is to move the variable to $rootScope.
The ui-router loads the PARENT view before the CHILD view. Now in order to send information from the CHILD back to the PARENT you need a globalized binding, which is found in $rootScope.

Thanks. The plkr told everything I need to know.

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

No branches or pull requests

6 participants