【问题标题】:How to do $state.go() with params?如何使用参数做 $state.go()?
【发布时间】:2016-06-17 11:00:53
【问题描述】:

我已经完美地初始化了 $stateProvider,并且我正在将所有这些状态与 ui-sref 一起使用。效果很好。 用户按下按钮并通过 $stateProvider 进入编辑页面。

在此页面上,我有一个执行 $http 请求的表单:

 this.pushData = function (data) {
        $http.post('/data/' + $stateParams.dataId + '/otherdata', JSON.stringify({
            id: otherdata.id, 
            name: otherdata.name
        }), configAuth).then(
            function success(response) {
                var addedData = response.data;
                $.notify({message: addedData.name + " has been added"},{type:'success'});

                $state.go('roleInfo({roleId: $stateParams.roleId})');
            },
            function error(data) {
                console.log(data);
                $.notify({message: data.data.message},{type:'danger'});
            }
        );

    }

如果一切正常,我想重定向到其他视图。但是这个:

$state.go('roleInfo({roleId: $stateParams.roleId})');

不起作用。如何使用参数执行 $state.go?

【问题讨论】:

    标签: javascript angularjs routing angular-ui-router angularjs-routing


    【解决方案1】:

    您尝试使用ui-sref 指令的方式,在使用$state.go 方法调用它时,您应该传递第一个参数是stateName,然后以Object 格式传递参数。

    $state.go('roleInfo', {roleId: $stateParams.roleId});
    

    【讨论】:

      【解决方案2】:

      试试这个:

      $state.go('myStateName', {roleId: $stateParams.roleId});

      You can read the docs here

      【讨论】:

        【解决方案3】:

        我变了 $state.go('roleInfo({roleId: $stateParams.roleId})');

         $state.go('roleInfo',{roleId :$stateParams.roleId});
        

        这会起作用


        this.pushData = function (data) {
                    $http.post('/data/' + $stateParams.dataId + '/otherdata', JSON.stringify({
                        id: otherdata.id, 
                        name: otherdata.name
                    }), configAuth).then(
                        function success(response) {
                            var addedData = response.data;
                            $.notify({message: addedData.name + " has been added"},{type:'success'});
        
                           $state.go('roleInfo',{roleId :$stateParams.roleId});                    },
                        function error(data) {
                            console.log(data);
                            $.notify({message: data.data.message},{type:'danger'});
                        }
                    );
        
                }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-10-31
          • 1970-01-01
          • 2016-02-17
          • 1970-01-01
          • 2016-03-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多