$stateparams 传递参数

根据链接地址传递参数

 

案例:界面显示订单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();
	}
})

//我的订单list
angular.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);
    };
}]);

 

操作步骤

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

 

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

 

 

 

 

 

 

 

你可能感兴趣的:($stateparams 传递参数)