首先,您必须在route中添加参数。
app.config(function($stateProvider) {
$stateProvider
.state('first', {
url: '/first',
templateUrl: 'first.html'
})
.state('second', {
url: '/second/:id',
templateUrl: 'second.html'
})
});
app.controller.('firstCtrl' ,["$scope", "$state", function($scope, $state){
$scope.userInput <- come from user
$scope.clickThis=function() {
$state.go("second", { id: $scope.userInput });
}
}]);
在第二个控制器中注入$ stateParams
//my second.html
app.controller.('secondCtrl',["$scope", "$state", "$stateParams", function($scope, $state, $stateParams){
$scope.id = $stateParams.id;
})