$stateparams 传递参数

来源:互联网 发布:regexbuddy mac 编辑:程序博客网 时间:2024/05/05 23:40

根据链接地址传递参数

 

案例:界面显示订单List,然后点击list查看订单详情

 

//家政订单详情.state('jiazhengOrderDetail', {url: '/jiazheng/jiazhengOrderDetail/:orderId',templateUrl: 'template/jiazheng/jiazhengOrderDetail.html',//ui-router的控制器引用其他service的方法,参数$state只能在$scope后面,否则会报错controller: "jiazhengOrderDetailController",onEnter: function(){$(".tabs-stable").hide();},onExit: function(){$(".tabs-stable").show();}})//我的订单listangular.module("jiazhengApp").controller("jiazhengMyOrderController", ["$scope", "$state", 'jiazhengMyOrderService', function ($scope, $state, jiazhengMyOrderService) {    jiazhengMyOrderService.getOrderList($scope);    $scope.showOrderDetail = function(orderid){        alert(orderid);        window.location.href="#/jiazheng/jiazhengOrderDetail/"+orderid;    }}]);//订单详情控制器angular.module("jiazhengApp").controller("jiazhengOrderDetailController", ["$scope", "$state", '$stateParams','jiazhengOrderDetailService', function ($scope, $state, $stateParams,jiazhengOrderDetailService) {    //判断参数是否传递过来    if($stateParams.orderId){        jiazhengOrderDetailService.getOrderDetails($scope,$stateParams.orderId);    }        //取消订单    $scope.cancelOrderFun = function(orderID){        alert(orderID);    };}]);

 

或者

$scope.showOrderDetail = function(orderid){$state.go("jiazhengOrderDetail",{"orderid":orderid});}

操作步骤

window.location.href="#/jiazheng/jiazhengOrderDetail/"+orderid;

 

//判断参数是否传递过来if($stateParams.orderId){    jiazhengOrderDetailService.getOrderDetails($scope,$stateParams.orderId);}

 

  

0 0
原创粉丝点击