使用 angularjs 动态 url 路由 [英] Dynamic url routing with angularjs

查看:33
本文介绍了使用 angularjs 动态 url 路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有类似的东西

I have something like that in my code

<ul ng-model="services">
   <p ng-repeat="item in items"><b>{{ item.name }}</b> 
   </p>

例如,我有 3 件商品:宝马、高尔夫和梅赛德斯我想要一个带有每个项目名称的 url,例如/bmw 或/mercedes,并且所有 url 都使用 details.html 来显示所选项目的详细信息.我正在努力了解如何做到这一点.

I have for example 3 items: BMW, golf and mercedes I want to have an url with the name of each item, like /bmw or /mercedes and all url use details.html to show the details of the selected Item. I'm trying to understand how can I do this.

推荐答案

你可以写一个像

.when('/car/:carId', {
  templateUrl: 'some/path/details.html',
  controller: 'someCtrl'
})

然后在控制器中,您可以使用 :carId 的值="nofollow">$routeParams

And then in the controller you can get the value of :carId using the $routeParams

这篇关于使用 angularjs 动态 url 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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