[英]Restful API calls from AngularJS and Query string
I am currently working on a web app where i have edit functionality.我目前正在开发一个具有编辑功能的网络应用程序。
Currently i build a page with a list of records which all contain the id.目前我构建了一个包含所有包含 id 的记录列表的页面。
So when i click on the edit button it does the following:因此,当我单击编辑按钮时,它会执行以下操作:
$state.go('editCustomer', { customerObj: customer });
This then directs to the edit page which shows the correct record and prepoulates the data which is fine.这然后指向编辑页面,显示正确的记录并预先填充好的数据。
However I wanted to do in a way where i click the edit button and it creates a url similar to the following: /customer?id=12345但是,我想以某种方式单击编辑按钮,它会创建一个类似于以下内容的网址:/customer?id=12345
When the edit pages loads it would then grab the id from the query string and call the get using $resource.当编辑页面加载时,它将从查询字符串中获取 id 并使用 $resource 调用 get。
So my question is how would i be able to do this?所以我的问题是我怎么能做到这一点? And would i need to change the api routing on the server side to accomodate this as currently is as follows for the get
我是否需要更改服务器端的 api 路由以适应这一点,因为目前对于 get 如下所示
router.get('/:id', controller.show);
Any help would be great任何帮助都会很棒
Thanks谢谢
<a ui-sref="editCustomer({ id: customer.id })">Edit</a>
This will create the correct URL for the route (something like: /customer/12345
).这将为路由创建正确的 URL(类似于:
/customer/12345
)。
This works for a route like this:这适用于这样的路线:
$stateProvider
.state('editCustomer', {
url: '/customer/:id',
// etc ...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.