zl程序教程

您现在的位置是:首页 >  后端

当前栏目

angular-ui-router state.go not passing data to $stateParams

AngularGoUI to not Data Router State
2023-09-11 14:20:10 时间

app.js中定义了一个state如下,url接收一个id参数

$stateProvider.state("page.details", {
            url: "/details/:id",
            templateUrl: "home/index.html",
            controller: "HomeCtrl",
            controllerUrl: "home"
        })

如果直接

$state.go('details');

将会显示state.go not passing data to $stateParams的错误信息,因为state的url中,已经规定需要传递一个id。
假如id没有值需要传递,如:

$state.go('details',{id:""});

假如需要传递id=1,如

$state.go('details',{id:1});

参考文献:

  1. state.go not passing data to $stateParams
  2. How to pass custom data in $state.go() in angular-ui-router?
  3. [ui-router \(stateProvider](https://ui-router.github.io/docs/0.3.1/#/api/ui.router.state.\)stateProvider#state)