nsr nsr - 2 months ago 7
AngularJS Question

How to get back the passed parameter $state.transitionTo?

i have a function called editDetails().. i am able navigate to viewproviderEdit.html page but how to receive parameter i passed in new controller

function

$scope.editDetails = function() {
console.log("id is ", id)
$state.transitionTo('app.viewproviderEdit', {stateParamKey: id});
}


app.router.js

.state('app.viewproviderEdit', {
url: '/view-provider-edit/:id',
templateUrl: 'manage_provider/viewproviderEdit.html',
controller: 'viewprovidereditCtrl',
resolve: {
deps: ['$ocLazyLoad',
function($ocLazyLoad) {
return $ocLazyLoad.load('xeditable').then(
function() {
return $ocLazyLoad.load('manage_provider/viewproviderEdit.js');
}
);
}
]
}
})


viewproviderEdit.js

app.controller('viewprovidereditCtrl', ['$scope', '$filter','$state',
function($scope, $filter,$state){
if($state.current.name === 'app.viewproviderEdit')
{
console.log("coming inside new controller");
// above console is working
}
}]);


How to get id in viewprovidereditCtrl controller. can anyone help me.

Answer
 $scope.editDetails = function() {
        console.log("id is ", id)
        $state.transitionTo('app.viewproviderEdit', {id:id});
      }

and change your controller

 app.controller('viewprovidereditCtrl', ['$scope','$filter','$state','$stateParams',
function($scope, $filter,$state,$stateParams){
    if($state.current.name === 'app.viewproviderEdit')
    {
        console.log("coming inside new controller");
        // above console is working
        console.log($stateParams.id);
    }
}]);

Use $stateParams for this :)