原理:

  1.在a标签跳转时,连接后增加一个参数值

  2.在路由中接收

  3.在控制器中接收

实现:

1.<a href="#/list/{{val.id}}">

2.js的config中写入:

.when('/list/:id', {
          templateUrl: 'views.route.detail.html',
          controller: 'RouteDetailCtl'
      })

3.angular中使用routeParams传递参数.

在controller中直接使用:

.controller('RouteDetailCtl',function($scope, $routeParams) {
    $scope.id = $routeParams.id;
})

就可以在接收页面获得id的值。

代码:

HTML片段:

<body ng-app="ngRouteExample" class="ng-scope">
<script type="text/ng-template" id="views.route.detail.html">
<h1> about</h1>
<span style="color:#ff6666;"><h1>{{id}}</h1></span>
</script> <script type="text/ng-template" id="embedded.home.html">
<h1> Home </h1>
</script> <script type="text/ng-template" id="embedded.about.html">
<h1> About </h1>
<span style="color:#ff6666;"><li ng-repeat="id in ID">
<a href="#/list/{{ id }}"> ID{{ id }}</a>
</li></span>
</script> <div>
<div id="navigation">
<a href="#/home">Home</a>
<a href="#/about">About</a>
</div> <div ng-view="">
</div>
</div>
</body>

js片段:

<script type="text/javascript">
angular.module('ngRouteExample', ['ngRoute'])
.controller('HomeController', function ($scope, $route) { $scope.$route = $route;})
.controller('AboutController', function ($scope, $route) { $scope.$route = $route;$scope.ID = [1,2,3];})
.controller('RouteDetailCtl',function($scope, $routeParams) {
$scope.id = $routeParams.id;
})
.config(function ($routeProvider) {
$routeProvider
  .when('/home', {
templateUrl: 'embedded.home.html',
controller: 'HomeController'
})
  .when('/about', {
templateUrl: 'embedded.about.html',
controller: 'AboutController'
})
  .when('/list/:id', {
templateUrl: 'views.route.detail.html',
controller: 'RouteDetailCtl'
})
  .otherwise({
redirectTo: '/home'
});
});
</script>

转载自:http://blog.csdn.net/it_huge/article/details/52441652。

angularjs之向下一个页面传参的更多相关文章

  1. jQuery 向另一个页面传参,同时跳转到该页面

    为了使参数能够传递到另外一个页面,使用ajax的跳转方式 $.ajax({ type: "POST", url:"/admin/sysjgl/sysjck/sjcs&qu ...

  2. AngularJS中页面传参方法

    1.基于ui-router的页面跳转传参 (1) 用ui-router定义路由,比如有两个页面,一个页面(producers.html)放置了多个producers,点击其中一个目标,页面跳转到对应的 ...

  3. 关于页面传参,decodeURI和decodeURIComponent

    之前写过一个关于页面传参的,但是是前端相对于自己的页面做的跳转,也就是页面1,跳转到页面2,里面带的参数.这里可以参考我上一篇文章,包括里面参数中如果有数组和json格式的情况.但是需要注意的是,我前 ...

  4. 用js把数据从一个页面传到另一个页面

    用js把数据从一个页面传到另一个页面的层里? 如果是传到新页面的话,你网站基于什么语言开发直接用get或者post获取,然后输出到这个层 通过url传参 如果是HTML页面的话JS传到新页面就wind ...

  5. vue 通过 name 和 params 进行调整页面传参刷新参数丢失问题&vue路由可选参数

    vue  通过 name 和 params 进行调整页面传参刷新参数丢失问题 router.js: export default new Router({ routes: [ { path: '/', ...

  6. Strut2页面传参跳转 --Struts2

    1.本案例借助struts2框架,完成页面传参.跳转功能 2.代码实现 index.jsp: <form action="helloStruts2.action" metho ...

  7. .net 页面传参方式总结

    一.使用Querystring Querystring是一种非常简单的传值方式,其缺点就是:安全性低.会把要传送的值显示在浏览器的地址栏中(也就是不需要保密得参数),并且在此方法中不能够传递对象,参数 ...

  8. FastAdmin 前端页面传参笔记

    FastAdmin 前端页面传参笔记 看到 QQ 群里的小伙伴询问如何传参,然后在社区里找到一笔记帖子 1 还要参考在线文档控制器部分2. 引用 Karson 的回复: 如果我们需要自己在控制器中透传 ...

  9. request设置属性 一般当做下一个页面的结果集

    request设置属性 一般当做下一个页面的结果集

随机推荐

  1. iOS常识名词解释 2016/04/05

    Bundle : http://www.cnblogs.com/BigPolarBear/archive/2012/03/28/2421802.html http://blog.sina.com.cn ...

  2. Luogu1155 NOIP2008 双栈排序 【二分图染色】【模拟】

    Luogu1155 NOIP2008 双栈排序 题目描述 Tom最近在研究一个有趣的排序问题.如图所示,通过 2个栈 S1 和 S2 ,Tom希望借助以下 44 种操作实现将输入序列升序排序. 操作 ...

  3. Luogu3387 缩点 【tarjan】【DP】

    Luogu3387 缩点 题目背景 缩点+DP 题目描述 给定一个n个点m条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点, ...

  4. ASP.NET Core 中的SEO优化(4):自定义视图路径及主题切换

    系列回顾 <ASP.NET Core 中的SEO优化(1):中间件实现服务端静态化缓存> <ASP.NET Core 中的SEO优化(2):中间件中渲染Razor视图> < ...

  5. ffmpeg && nginx hls

    备注: 使用ffmpeg 将视频转换为hls,并使用nginx 提供服务,实现点播功能,没有使用rtmp 插件 1.  ffmpeg 命令生成文件 a. ts ffmpeg -y -i mydemo. ...

  6. caddy quic 协议试用&& 几个问题

    备注:    caddy  具体的安装就不介绍,quic 协议也不介绍了   1. 启用协议,比较简单 /usr/local/bin/caddy -log stdout -quic -conf=/et ...

  7. 转 neighbour table overflow 问题解决

    接到保障,说某来机器服务没法访问,于是,准备连接到机器上去看个究竟. 尼玛居然连不上,连ping都ping不通,无奈只能求助机房. 机房人员检查, 发现报 neighbour table overfl ...

  8. 【转】刚发现一个linux在线文档库。很好很强大。

    原文网址:http://blog.csdn.net/longxibendi/article/details/6048231 1.网址: http://www.mjmwired.net 2.比如查看这个 ...

  9. bzoj 1001 [BeiJing2006]狼抓兔子——最小割转最短路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1001 #include<cstdio> #include<cstring& ...

  10. TOMCATE8下面项目启动问题

    1.将servlet-api.jar替换项目中的servlet-api2.4 2.<servlet>           <servlet-name>dwr-invoker&l ...