zoukankan      html  css  js  c++  java
  • 关于ionic传值

    今天,也是偶然发现有的初学者对ionic的传值还不太清除,这里我说明一下

    例如你想在这个页面传递参数a、b过去,传递到"tab.wait"页面

    $state.go("tab.wait",{a:123,b:456});等等后面可以跟很多参数


    然后看 tab.wait

    .state('tab.wait', {
    url: '/tab_wait',
    params:{"a":null,"b":null},
    views: {
    'tab-love': {
    templateUrl: 'templates/wait.html',
    controller: function($scope,$stateParams) {
    $scope.hehe=$stateParams.a       -> 弹一下$scope.hehe,你就可以得到 123 因为a传过来的值是123
    $scope.heihei=$stateParams.b     -> 弹一下$scope.heihei,你就可以得到 456 因为b传过来的值是456

    }
    }
    }
    })

    如上所示,在路由tab.wait里面加入 params:{"a":null,"b":null}初始化一下,你有几个参数就把几个参数初始化
    然后注入依赖,如在controller: function($scope,$ionicPopup,$timeout,$stateParams)里面注入$stateParams
    然后你tab.wait对应的页面里面就可以获得到传过来的值了,如tab.wait页面里面有一个

    <p>{{hehe}}</p>和

    <p>{{heihei}}</p>
    那就可以 $scope.hehe=$stateParams.a      -> 弹一下$scope.hehe,你就可以得到 123 因为a传过来的值是123,这是把传过来的东西$stateParams.a赋值给$scope.hehe,用于页面展示
    $scope.heihei=$stateParams.b         -> 弹一下$scope.heihei,你就可以得到 456 因为b传过来的值是456,这是把传过来的东西$stateParams.b赋值给$scope.heihei,用于页面展示

    这就是$state.go()的传值 ,ui-sref是一样的,只不过是在页面中把传值给传了,例如
    ui-sref=“tab.detail({a: 1, b: 2})” 同样在目标页面注入 params:{"a":null,"b":null}记得这个params后边是个逗号,别忘了 ,注入依赖$stateParams ,然后根据$stateParams.a或者$stateParams.b拿到传过来的值

  • 相关阅读:
    matlab中输入x. 与x的区别
    nginx 访问控制之deny allow
    nginx 反向代理之 负载均衡
    http 缓存机制简介
    nginx 反向代理之 proxy_cache
    nginx 反向代理之 proxy_buffering
    nginx 反向代理之 proxy_redirect
    nginx 反向代理之 proxy_set_header
    nginx 反向代理之 proxy_pass
    nginx 反向代理配置示例
  • 原文地址:https://www.cnblogs.com/zyl521531/p/6209814.html
Copyright © 2011-2022 走看看