-
Notifications
You must be signed in to change notification settings - Fork 3k
Feature req: access to sub-view from a controller #1259
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
This doesn't make sense. If you have an |
My bad, copy paste error, both controllers are the same. |
Personally, I've done stuff like this. I moved as much redundant logic into a service, and made the controllers contain the only distinguishable code. |
Let me go into more details on the why of this :) |
Let me ask you this, is it a big problem to create AController and BController instead of reusing AController? |
Well, that's the same as doing an intermediate template with a different scope which I ended up doing in the end. I still think it to be kind of weird when both logic are the same and easily avoidable if the controller knew which view object instantiated it in the $state config. |
It's so odd, like the entire problem only exists because you have 2 controllers on the same view. Any other combination and there wouldn't be a problem. I don't like having arbitrary data, I feel like if the controller could introspect which view it's on you could figure out the rest. |
Not same view, same state but yup, if the controller could introspect the view that instantiated it, it would be easy :) |
Does ui-router handle controller-as-scopeName? |
hmm, I think so. Do you think that could help out ? I'll dig into it ! |
You could do 'Controller as AController' and 'Controller as BController' and then inside the controller have |
@ProLoser Works like a charm ! 👍 |
What? No I was exactly referring to doing it from inside the controller, but whatever works. Glad we could knock one more bug off the list. |
Yes it's inside the controller, but i mean, you have to wait for the $stateChangeSuccess to have a value associated with the controller alias:
This outputs null and false.
This correctly works :) |
Hello,
I was wondering if this was possible.
Say I have a state defined like this:
I have basically two "nearly" identical sections on a webpage that have the same template + controller.
For the sake of it, think of a form section that is visible at 2 areas, but with different behaviours. If I have submit from the first section, I'd like to redirect to the first section, if not, to the second.
Knowing this, I stupidly thought that I could add a data param to the view, and check it in the controller.
However, there is now way to determine (to my knowledge) which view a controller is associated to with the $state service.
My workaround has been to create sub template for both section with an
ng-include
of theA.html
and have ang-init = "section = X;"
so that a new scope is created for each section, but it seems kind of hacky/redundant, if only similar to $stateParams, there could be some kind of a $viewData service?Any thoughts?
Thanks!
The text was updated successfully, but these errors were encountered: