zoukankan      html  css  js  c++  java
  • angular 跳转页面时传参

    首先,你需要已经配置过你的rout,比如:

    $stateProvider
                .state('firstPage',{
                    url:'/Page/firstPage',
                    templateUrl: 'Page/views/firstPage.html',
                    controller: 'firstPageCtrl'
                    //dependencies: ['service/vipSeachService']
                })
              
                .state('secPage', {
             params:{'message':null}, url:
    '/Page/secPage', templateUrl: 'Page/views/secPage.html', controller: 'secPageCtrl' })

    其中注意第二个地址信息中的params属性,这个就是你要接受参数的对象,以key :value的形式定义

    而在跳转页面时,两个方法都可以传参,一种是直接写在html中

    <a ui-sref="sec-page">跳转第二页</a>

    此时传参跟在页面地址的后面

    <a ui-sref="sec-page({message:messageId})">跳转第二页</a>

    第二种就是写在controller中

    .controller('firstPageCtrl', function($scope, $state) {
      $state.go(
    'secPage');
    });

    同样参数写在地址后面,以对象的形式

    .controller('firstPageCtrl', function($scope, $state) {
       $state.go('secPage',{message:messageId}); 
    });

    传过去的参数,需要在目标页面的controller中用$stateParams接收,改方法需要提前注入

    .controller('secPageCtrl', function($scope, $state,$stateParams) {
       var test=$stateParams.message;
    });
  • 相关阅读:
    SQL常规查询详解
    WEBGL学习【二】平面图形
    WEBGL学习【一】初识WEBGL
    VS2008集成QT的OpenGL开发(实现二维图形的旋转)
    Window文件路径
    字符串转DateTime
    字符串连接
    String.Split分隔字符串
    使用对象初始值设定项初始化
    表达式树
  • 原文地址:https://www.cnblogs.com/weblv/p/5717890.html
Copyright © 2011-2022 走看看