Skip to content

ui-router doesn't run the current state if your ui-view is inside an ng-include #679

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

Closed
nickretallack opened this issue Dec 14, 2013 · 33 comments

Comments

@nickretallack
Copy link

ng-include a template that has a ui-view in it. When the page loads, ui-router won't run the current state. Navigate to a new url and back and the state will run.

@timkindberg
Copy link
Contributor

Would you mind creating a plunkr that recreates the issue?

@nickretallack
Copy link
Author

I would, but I don't know how to do an ng-include in plunker.

On Friday, December 13, 2013, Tim Kindberg wrote:

Would you mind creating a plunkr that recreates the issue?


Reply to this email directly or view it on GitHubhttps://github.com//issues/679#issuecomment-30557738
.

@nickretallack
Copy link
Author

Ok I modified the example plunker to show what I mean.
http://plnkr.co/edit/xnaX6Q?p=preview

I noticed that if there are any ui-sref directives on the main page, the problem doesn't arise.

@nickretallack
Copy link
Author

Btw, the reason I'm not using ui-sref is because I need to have a link within a link. That is, an element is clickable and so is its parent element. This unfortunately can't be done with anchor tags. Is there a way to do this with ui-sref?

<div ng-click="go_to_subview()">
<a href="page.html">Title</a>
<p>Info</p>
</div>

It makes more sense for the inner link to be the real link because it opens a different page, and you might want to use control-click on it.

@timkindberg
Copy link
Contributor

Why yes, you can: https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-prevent-nested-ui-sref-objects-from-all-firingtriggering. There was an issue opened about this already, but we decided for now to just use the method shown in that link.

Also that plunkr is working for me, am I supposed to see something break?

@nickretallack
Copy link
Author

Yes it's broken. It doesn't show an error or anything, but you can discover the oddity by experimenting with it a little. The bug is that ui-view or ui-sref tags in the included template (template.html) do not cause ui-router to start working. See how route1 is not rendered, even though it's supposed to redirect you there and render that immediately? If you add a single one of these tags to the outside template (index.html) it suddenly decides to redirect you and render the ui-view in the included template.

I noticed a new oddity while I was making this plunker. In my initial bug report, I was reloading the page while the url already matched route1 and it wouldn't render the template. By playing with this, I've further discovered that it won't redirect you to route1 unless there are ui-view or ui-sref tags in the main template (index.html).

@nickretallack
Copy link
Author

The reason I'm doing a top level include is so my template can escape from the server-side templating engine, which uses the same mustache notation as angular. Unfortunately, it seems I need to put some ui-* directives outside the top level include in order to get ui-router to boot.

@timkindberg
Copy link
Contributor

Hmmm, that is quite interesting. If I add ui-sref to basically anywhere in index.html, then route1 is properly loaded, if I remove it then it breaks again.

@dlukez
Copy link
Contributor

dlukez commented Dec 23, 2013

This sounded similar to angular/angular.js#4957

...so I made a small modification to your plunkr whereby a run function block includes the $state service:

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

Does that work as expected?

@matthewpavkov
Copy link

I ran into this same issue, and @dlukez suggestion fixed the issue.

@jgoldberg
Copy link

+1 to @dlukez fix

@santyclaz
Copy link

Using @dlukez workaround, but would very much prefer the root cause fixed.

@shaneeb
Copy link

shaneeb commented Apr 28, 2014

+1 @dlukez fix but agree that the workaround should not be needed

@jphire
Copy link

jphire commented May 10, 2014

+1 @dlukez, also preferring the root cause fixed

@ericpeters0n
Copy link

+1

Just ran into this (ng-include of template with ui-view being quietly ignored by ui-router)... Will try the workaround, but it seems preferable that what should work with kosher angular should also work with ui-router.

@dlukez
Copy link
Contributor

dlukez commented Aug 3, 2014

@ericpeters0n last I checked this is also an issue in angular's ng-view

@exocom
Copy link

exocom commented Oct 2, 2014

+1 just ran into this while switching from ng-view to ui-view.
@dlukez workaround worked for us, now I can really start testing out ui-router and see if it will works for us. We haven't had any issues with ng-view inside of ng-include, however, we are manually bootstraping the app.

@dlukez
Copy link
Contributor

dlukez commented Oct 3, 2014

I once tried fixing this for ng-view because it used to have the same problem, but I broke other stuff and gave up on it. It sounds like maybe they've fixed it now though, so I might take a look at their new implementation and see if I can figure out a way to port it here

Sent from my iPhone

On 3 Oct 2014, at 7:25 am, exocom [email protected] wrote:

+1 just ran into this while switching from ng-view to ui-view.
@dlukez workaround worked for us, now I can really start testing out ui-router and see if it will works for us. We haven't had any issues with ng-view inside of ng-include, however, we are manually bootstraping the app.


Reply to this email directly or view it on GitHub.

@dlukez
Copy link
Contributor

dlukez commented Oct 22, 2014

Doesn't look like it's fixed in Angular yet :(

@dallonf
Copy link

dallonf commented Jan 13, 2015

Also seeing this issue. Also can report the workaround helps.

For anybody who might be using Jade, here's a quick gotcha: div(ui-view) compiles to <div ui-view="ui-view"></div>. What you need is div(ui-view=""). Not sure if that's useful to anybody else in this thread, but it wasted a good half hour of my time thinking the workaround wasn't helping.

@carlos-algms
Copy link

+1.
I want to make a dynamic template engine that expose ui-view inside a ng-include.

@ilyagelman
Copy link

+1

@nickretallack
Copy link
Author

This is still tripping people up a year later?

@ilyagelman
Copy link

Well, it only works for me if I inject $state at the run state.

@theghostbel
Copy link

.run() hack-fix helped us, but "vanilla-angular" support is really needed, so, +1

@tslater
Copy link

tslater commented Feb 19, 2015

+1

@nateabele
Copy link
Contributor

I'll look into this when I have time, but for now, there are plenty of equally-problematic issues that don't have simple workarounds, so I can't logically prioritize this.

If someone else wants to dig into it and report back (or better yet, open a PR), that'd be great.

@uditalias
Copy link

+1

@Kaijun
Copy link

Kaijun commented Jun 25, 2015

same here, but i found a solution as @ilyagelman mentioned:

    .run(['$state', function($state){

    }]);

will fix, but donno why...

mathiasslawik added a commit to TU-Berlin-SNET/tresor-broker that referenced this issue Jul 7, 2015
@BilalBoulifa
Copy link

+1

@justechn
Copy link

I am having a similar problem, but adding .run does not fix it
http://plnkr.co/edit/Na5zkF?p=preview

The xxx button at the top should open a sidenav, just like the big button in the body, and next to the xxx button should be a title. Neither of those are working because they are included in an ng-include

@ps1dr3x
Copy link

ps1dr3x commented Jan 17, 2017

Same here, .run solution doesn't work

@stale
Copy link

stale bot commented Jan 24, 2020

This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues
may be reopened.

Thank you for your contributions.

@stale stale bot added the stale label Jan 24, 2020
@stale stale bot closed this as completed Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests