anuglar.js ui-router传递参数

anuglar.js ui-router 传递参数的方法有:html

一: ui-sref 传递参数,传递一个参数的时候ui

首先路有这样写:url

  

.state('edit', { //线路编辑页面
		
		url: '/edit?id',
		
		templateUrl: 'view/template/shopList/edit.html',
		
		controller: 'editCtrl'
		
	})

  html 页面写法为:spa

<button ui-sref="edit({id:{{item.id}}})" type="button" class="btn btn-link btn-sm">编辑</button>
{{item.id}}是动态的数据

controller 中获取传递的参数的方法code

$state.params.id
能够打印 $state.params 看看结果

传递多个参数的时候:router

路由的写法为:
htm

.state('edit', { //线路编辑页面
        
        url: '/edit?id&page',
        
        templateUrl: 'view/template/shopList/edit.html',
        
        controller: 'editCtrl'
        
    })

url: '/edit?id&page',
须要传递多少参数,便在问号后边跟上就行

html 页面写法为:blog

<button ui-sref="edit({id:{{item.id}},page:{{item.id}}})" type="button" class="btn btn-link btn-sm">编辑</button>

 

controller 中获取传递的参数的方法,仍是跟之前同样。路由

 

一:$state.go 传递参数,传递一个或者多个参数的时候(直接写多个一个和 ui-sref 同样的写法)it

路由写法

.state('home', {
        
        url: '/home?id&page',
        
        templateUrl: 'view/home.html',
        
        controller: 'homeCtrl'
        
    })

控制器写法:

 $state.go('home',{id: '01',page: '02'});

接受参数的写法:

    console.log($state.params);接受参数的时候有两种写法都是同样的:$state.params.id  或者  $stateParams.id
相关文章
相关标签/搜索