+1 ui-router. It's much more flexible than the built-in routeProvider and it allows easier builds for complex UI interfaces.
On Thursday, 27 February 2014 22:30:01 UTC+8, Steve Jackson wrote: > > +1 for angular-ui-router! We're using it with great success to do exactly > what you describe, Andy. > > Steve > > > On Thursday, February 27, 2014 1:29:05 AM UTC-5, Luke Kende wrote: >> >> If you need nested views where parent view needs to maintain state after >> going from /admin to /admin/user/cf23df2207d99a7, and you are going to >> have a lot of these, or multiple nestings, then I suggest ui-router: >> https://github.com/angular-ui/ui-router >> >> Personally, it was more than I needed so instead of ng-view I use >> ng-include and $watch for $routeChangeSuccess : >> >> $routeProvider >> .when('/admin', { >> templateUrl: '/partials/admin.html' >> }) >> .when('/admin/user/:user_hash', { >> templateUrl: '/partials/admin.html' //notice it's same template >> because will be handled >> }) >> >> <body ng-controller="MainCtrl"> >> <header></header> >> <div ng-include="currentTemplate"></div> >> <footer></footer> >> </body> >> >> >> function MainCtrl($scope, $route){ >> >> //scope for main controller that lives for the lifetime of the page - >> don't bloat it with stuff for all views >> $scope.headerStuff = ... >> $scope.footerStuff = .... >> >> $scope. currentTemplate = '/partials/empty.html'; //temporary for first >> load >> >> $scope.$on('$routeChangeSuccess',function(){ >> >> /* here you catch the change without having ng-view force you in to >> loading it's template and controller >> I can make my own logic on whether to load a new template, or not and >> let the controller in >> admin template also catch the routechangesuccess and it can use >> ng-include or ng-switch as it needs >> - now we have a way to map routes and manage them more under our >> control >> */ >> >> if ( $scope. currentTemplate != $route.current.templateUrl){ >> $scope. currentTemplate = $route.current.templateUrl; >> } >> >> }) >> } >> >> //admin partial >> <div ng-controller="AdmingCtrl"> >> <div id =adminStuff"></div> >> <div ng-include='innerTemplate'></div> >> </div> >> >> function AdminCtrl($scope, $routeParams){ >> >> $scope.adminStuff = ... >> >> $scope. innerTemplate = 'parials/empty.html'; //for when nothing needs >> to be here >> >> $scope.$on('$routeChangeSuccess',function(){ >> >> $scope.user_hash = $routeParams.user_hash; >> $scope. innerTemplate = 'admin.user.html' //now we load the user >> template >> >> }) >> } >> >> Anyway, this might be too bit to digest as a newbie, but maybe it will >> plant the seed to think outside the box. >> >> On Wednesday, February 26, 2014 7:40:31 PM UTC-7, Andy Czerwonka wrote: >>> >>> Angular newb here. >>> >>> I just want to make sure I've got this right. >>> >>> 1. When I want addressable URL's I should use ng-view and load partials >>> using the $routeProvider to bind local controllers to specific URL's. >>> 2. State inside a particular controller should be managed using scope >>> variables, i.e. don't try and build nested views. >>> >>> I'm trying to follow https://github.com/IgorMinar/foodme as a working >>> example, but it's a fairly trivial example that doesn't go anywhere near a >>> complex structure. For example, if I have an /admin endpoint and within >>> that I wanted to do user admin and maybe some configuration of some kind, I >>> would expect something like /admin/user and /admin/configuration as >>> addressable endpoints. If I want something like that, is there a best >>> practice? I was using ng-switch to get the right page once in the >>> /adminpartial, but everything lives under >>> /admin. If I want to take it further and get to >>> /admin/user/cf23df2207d99a7, then I'm in trouble. >>> >> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
