zoukankan      html  css  js  c++  java
  • 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。

  • 相关阅读:
    软件质量保证体系是什么&#160;国家标准中与质量保证管理相关的几个标准是什么?他们的编号和全称是什么?
    软件测试分为几个阶段&#160;各阶段的测试策略和要求是什么?
    BUG管理工具的跟踪过程(用BugZilla为例子)
    多线程
    设计模式
    一个简单的layui登陆界面
    反射技术
    Win10繁体——简体
    Vue学习—组件的学习
    IDEA 相关问题
  • 原文地址:https://www.cnblogs.com/s313139232/p/7326389.html
Copyright © 2011-2022 走看看