0

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.