• angularjs之向下一个页面传参


    angularjs之向下一个页面传参

    原理:

      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。

  • 相关阅读:
    HTML5中input输入框的种类
    perl mojo 编码
    perl encode_utf8 decode_utf8
    perl mojo use utf8 和no utf8
    perl unload oracle gbk
    perl unload Oracle utf8 数据库
    perl socket 返回发送成功数据的长度
    perl socket 客户端发送消息
    验证码识别(Tess4J初体验)
    Uploadify 3.2 参数属性、事件、方法函数详解
  • 原文地址:https://www.cnblogs.com/s313139232/p/7326389.html
Copyright © 2020-2023  润新知