-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Bug: ng-view required for routing #1580
Comments
How will you handle routes without multiple templates? I'm genuinely curious so I can understand how best to tackle your question. There's still a possibility that ng-view and the routing around that would work for you. |
So I'm re-writing an app I built called HubSearch (it's a better github search). http://projects.jga.me/hubsearch/ It's a very simple app that really only has two states (without search results and with search results). I built it with only one controller and one template, but it has two routes: / and /:language/:query. Both routes go to the same controller and both use the same template. So rather than using the automatic routing, I'm watching for the $routeChangeSuccess event and passing that on to the controller. In that scenario, how would you structure your controllers and routes? You can see my progress here: https://github.com/jgallen23/hubsearch/tree/feature/angular |
You can have multiple routes go to a single controller. You just have to check out your $routeParams and determine what you want to do based on that. |
I can't seem to get that to work either: http://jsfiddle.net/3hy8P/5/ |
Here's a simple example |
Thanks. I was trying to get away from using a template in the route, but I guess that's not possible at this time. I think the bug is still valid because if I want to do custom routing, the events shouldn't only fire if an ng-view exists. |
Where do you want the template to be? Or do you not want templates at all? I agree about the ng-view coupling unless a more experience dev knows something about this. |
Thanks for your help. I'm going to re-work my app to use ng-view and templates. |
Closing this one as this seems to be more a general question than a bug report. @jgallen23 there is a mailing list dedicated to AngularJS (angular@googlegroups.com), in the future try to ask there is you are not sure if you are dealing with a bug. There are many people present on the mailing list and will be happy to help you. @jtymes Thnx a lot for helping out! |
@pkozlowski-opensource I still think it's a bug that routeProvider doesn't fire events unless an ng-view is in the markup. If nothing else, it should be in the documentation. |
I think this should be reopened and addressed. I have a page in which I use the router for hash parsing convenience and to respond to changes in the hashpath, but the information in the path is insufficient for determining which view to load (and I can't put that info in the url as that will clutter it up and disobey our site's url scheme). I'm using ng-include to load the correct partial once the url is available, but I still want to be able to have the router. Currently this means a hidden element with ng-view on it that loads an empty template on every route, but that shouldn't be necessary in my opinion. Just let me know if I should file a separate issue for this. |
@nicolacity It seems to me that you're using the If you still think it's a problem with Angular and you are indeed using Thanks! |
I think the plan of extracting url parsing is a good one. |
I also have a scenario where I use the $route module without binding routes strictly to a view. My app consist of several gui layers which are shown in several visible/invisible combinations (with ng-if). One controller is responsible for manipulating the scope for the layer combinations. The route dictates which combinations are shown. This controller is there for the lifetime of the application. The routing validates the url patterns using resolve. The layer controller listens to the routechange events and adjusts the gui as necessary. Works like a charm, except for the non used ng-view in the markup. |
I have an app that I would like to do some custom routing for. I'd rather not use multiple controllers and templates for my routes and I'd like to handle the routes myself. I've found that when I listen to the $routeChangeSuccess event, it will only fire if there is an ng-view on the page. Here are is the code:
Not working: http://jsfiddle.net/mxdPq/9/
Working: http://jsfiddle.net/mxdPq/10/
I'm not really sure if this is a bug or just not clear in the documentation. I don't think I should have to use an ng-view with a routeProvider, but I'm still pretty new to angular and still learning the ropes.
The text was updated successfully, but these errors were encountered: