错误:无法解析' user / show / {id:.....}'来自州''

时间:2015-03-21 15:03:39

标签: angular-ui-router sails.js

我正在使用Angular stateprovider的Sailsjs应用程序。我想通过身份证传递网址。我尝试了更多方法来传递带有id的stateprovider。我收到了这样的错误Error: Could not resolve 'user/show/{ id: ..... }' from state '

我的代码示例

app.js

    .state('user/show/', {
                url: '/user/show/:id',
                templateUrl: '/user/show',
                 controller:'secondCtrl'
    })

...

app.controller('secondCtrl',["$scope", "$state", "$stateParams"], function ($scope, $state, $stateParams){
    $scope.id = $stateParams.id;

    $state.go('user/show/:' +  $scope.id );
})

html page

<a ui-sref="user/show/{ id: <%= session.User.id %> }"> <i class="fa fa-user"></i></a></a>

错误

 Error: Could not resolve 'user/show/{ id: 54edd37704bc7d952524bfe1 }' from state ''
    at Object.x.transitionTo (http://localhost:1338/js/dependencies/angular-ui-router.min.js:7:16186)
    at Object.x.go (http://localhost:1338/js/dependencies/angular-ui-router.min.js:7:15755)
    at http://localhost:1338/js/dependencies/angular-ui-router.min.js:7:23364
    at http://localhost:1338/js/dependencies/angular.min.js:108:321
    at e (http://localhost:1338/js/dependencies/angular.min.js:31:267)
    at http://localhost:1338/js/dependencies/angular.min.js:34:398

但页面无法更改.. 所以,请帮助我......

1 个答案:

答案 0 :(得分:0)

StateProvider没有以这种方式工作。您没有名称为user/show/:的州,因此您无法解决此问题。

尝试:

$state.go('user/show/', {
    id: $scope.id
});