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;
    });
  • 相关阅读:
    2014最后一篇英语笔记(新开始)
    记录:CSS特殊性——权值规则
    grunt--自动化打包工具使用
    【移动端】---点透事件
    [前端性能提升]--图片转化为base64
    js--cookie
    1.倒数几秒弹窗关闭
    ES6就是ES2015 的主要内容
    call 与 apply的区别
    34枚金币时间管理法
  • 原文地址:https://www.cnblogs.com/weblv/p/5717890.html
Copyright © 2011-2022 走看看