AngularJS:多个编辑表单路由? [英] AngularJS: multiple edit forms routing?
问题描述
我有一个 Requests 列表,每个 Requests 都有一个 Request_Type_Id,它映射到一个 feeder 列表(它会随着应用程序的发展而增长).例如,我们可能有 (id, request_type) 1 - 销售信息,2 - 技术支持,3 - 订单信息,当然,每个字段都有唯一的字段,因此编辑表单非常不同.
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.
对于路由,我有这个:
$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>
我仍在尝试学习 AngularJS,并且想知道从这里开始的最佳方法是否是使用 ng-show 在/App/Views/editRequest.html 上选择正确的编辑表单.这意味着该模板上至少会有 3 个表单(但不是嵌套的),这在某些浏览器中可能会出现问题.
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.
是否有更多的 AngularJS 方法可以做到这一点我还没有学过?
Is there a more AngularJS way to do this that I haven't learned yet?
提前致谢!
推荐答案
templateUrl
可以是字符串或函数,它接受路由参数并返回一个字符串.
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: '/' } );
这里值得一提的另一件重要事情是,在href
或src
中使用插值时要小心.使用 ng-href
或 ng-src
.
Another important thing worth mention here is, be careful when use interpolate in href
or src
. Use ng-href
or ng-src
instead.
这篇关于AngularJS:多个编辑表单路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!