I am new to angular, I want to know if angularjs supports nested routes like emberjs I mean routes like this: myappurl/#/company/:company_id/department/:department_id
3 Answers
It worth mentioning there are another Angular libraries except ui-router to accomplish this task. This one works too:
http://angular-route-segment.com
It is much simpler to use than ui-router. Sample route configuration looks like this:
$routeSegmentProvider.
when('/section1', 's1.home').
when('/section1/prefs', 's1.prefs').
when('/section1/:id', 's1.itemInfo.overview').
when('/section1/:id/edit', 's1.itemInfo.edit').
when('/section2', 's2').
segment('s1', {
templateUrl: 'templates/section1.html',
controller: MainCtrl}).
within().
segment('home', {
templateUrl: 'templates/section1/home.html'}).
segment('itemInfo', {
templateUrl: 'templates/section1/item.html',
controller: Section1ItemCtrl,
dependencies: ['id']}).
within().
segment('overview', {
templateUrl: 'templates/section1/item/overview.html'}).
segment('edit', {
templateUrl: 'templates/section1/item/edit.html'}).
up().
segment('prefs', {
templateUrl: 'templates/section1/prefs.html'}).
up().
segment('s2', {
templateUrl: 'templates/section2.html',
controller: MainCtrl});
3 Comments
Suamere
In the example, would section.html ever be hit?
/section1 is routed to the s1 .. home segment, right? If I'm right, it is misleading to have a templateUrl defined in the s1 segment. Then the question... does the MainCtrl for the s1 segment become a parent controller to the Section1ItemCtrl?artch
It is a nested view hierarchy.
home.html is included into section1.html, and so forth. All controllers are inside a prototypal scope chain. You can see this example live here: angular-route-segment.com/src/exampleAlberto Acuña
@artch how can u do this? I go Section1, then i go to Item 5 (inside section1), now i go to Section2, now i click on Section1(it reestar pages, BUT I WAMMA REOPEN ITEM5) im not sure if u understand what im saying
According to the example given in the document: https://docs.angularjs.org/api/ngRoute/directive/ngView. Yes, Angularjs supports it.
1 Comment
Cherif BOUCHELAGHEM
Thank you so much the frontend developer in my team was very happy :) we missed it.