AngularJS:多个编辑表单路由? [英] AngularJS: multiple edit forms routing?

查看:243
本文介绍了AngularJS:多个编辑表单路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有映射到给料器列表(如应用程序的发展可能生长)一个Request_Type_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.

有关路由,我有这样的:

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>

我仍然努力学习AngularJS,我想知道,如果从这里出发的最好方法是使用NG-节目选择上/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆