Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to $state.go()

Is my $stateProvider:

$stateProvider
.state('home', {
    url : '/',
    templateUrl : '/admindesktop/templates/main/',
    controller : 'AdminDesktopMainController'
}).state('company', {
    url : '/company',
    templateUrl : '/admindesktop/templates/grid/',
    controller : 'CompanyGridController'
}).state('company.detail', {
    url : '/{id:\d+}', //id is 
    templateUrl : '/admindesktop/templates/company/detail/',
    controller : 'CompanyDetailController'
});

It's work for 'company' state (I use ui-sref), but this code not work (called from 'company' state):

$state.go('.detail', {
    id: $scope.selectedItem.id //selectedItem and id is defined
});

I read official docs and answers from StackOverflow, but I don't found solution. I can't use ui-sref, I use ui-grid, and new state opened after select one row from table for editing.

What i do wrong?

like image 759
Dunaevsky Maxim Avatar asked Jan 20 '15 10:01

Dunaevsky Maxim


People also ask

What is state go in js?

$state.go can be used to redirect to some page.

What is the use of state go?

To load the current state.

What is state in AngularJS?

$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.

What does UI sref do?

A ui-sref is a directive, and behaves similar to an html href . Instead of referencing a url like an href , it references a state. The ui-sref directive automatically builds a href attribute for you ( <a href=...> </a> ) based on your state's url.


1 Answers

To load the current state. Check this out.

$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams

Reference

like image 91
krunal.cp Avatar answered Oct 11 '22 13:10

krunal.cp