How to do $state.go() with params?
Asked Answered
S

3

5

I have perfectly initialized $stateProvider and I'm using all this states with ui-sref. Works great. User presses the button and thorugh the $stateProvider goes to the edit page.

On this page I have a form which does $http request:

 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'});
            }
        );

    }

And I want to do redirect to other view if everything is fine. But this:

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

doesn't work. How can I do $state.go with params?

Stuckey answered 17/6, 2016 at 11:0 Comment(0)
W
5

The way you are trying that would work with ui-sref directive, while calling it using $state.go method, you should pass 1st parameter is stateName & then pass params in Object format.

$state.go('roleInfo', {roleId: $stateParams.roleId});
Weasel answered 17/6, 2016 at 11:5 Comment(0)
D
3

Try this:

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

You can read the docs here

Disentwine answered 17/6, 2016 at 11:4 Comment(0)
R
2

i have changed $state.go('roleInfo({roleId: $stateParams.roleId})'); to

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

this will work


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'});
                }
            );

        }
Rains answered 17/6, 2016 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.