Question

I have a listing of Requests each with a Request_Type_Id which maps to a feeder list (which could grow as the application evolves). For example, we might have (id, request_type) 1 - Sales Information, 2 - Technical Support, 3 - Order Information and, of course, each one has unique fields so the edit forms are very different.

By clicking the name, I want to open the correct of these different edit forms.

For routing, I have this:

$routeProvider
    .when('/editrequest/:req_id/:id', {
       controller: 'EditRequestController',
       templateUrl: '/App/Views/editRequest.html'      
    }).otherwise( { redirectTo: '/' } );

because I set the edit link to

<a href="#/edit/{{req.request_Id}}/{{req.id}}">{{req.title}}</a>

I am still trying to learn AngularJS and am wondering if the best way to proceed from here would be to choose the correct edit form on /App/Views/editRequest.html by using ng-show. This would mean there would be at least 3 forms on that template (not nested, though) which might be problems in some browsers.

Is there a more AngularJS way to do this that I haven't learned yet?

Thanks in advance!

Was it helpful?

Solution

templateUrl can be a string or a function, which accepts route parameters and return a string.

In your case, you can doing so:

$routeProvider
.when('/editrequest/:req_id/:id', {
   controller: 'EditRequestController',
   templateUrl: function(params) {
     // use params.req_id to generate a url
     return '/App/Views/editRequest'+params.req_id+'.html';
   }
}).otherwise( { redirectTo: '/' } );

Another important thing worth mention here is, be careful when use interpolate in href or src. Use ng-href or ng-src instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top