How to $state.go() in Angularjs?

Today, We want to share with you state go in angularjs.In this post we will show you angularjs stateprovider, hear for angularjs $stateprovider.state params we will give you demo and example for implement.In this post, we will learn about Removing # hash from URL in AngularJS with an example.

state.go angularjs tutorial

to string Absolute state name or relative state path.

Good examples:

  • $state.go(‘contact.detail’) – will go to the contact.detail state
  • $state.go(‘^’) – will go to a parent state
  • $state.go(‘^.sibling’) – will go to a sibling state
  • $state.go(‘.child.grandchild’) – will go to grandchild state

How to send parameters in Angularjs $state.go?

Example 1:

$stateProvider
.state('SignUpMember.OTPVerification', {
    url: '/SignUpMemberOTPVerification',
    params: {
        customerid: null,
        OTP: null
    },
    templateUrl: 'SignUpMember/SignUpMemberOTP.html',
    controller: 'SignUpMemberOTPVerification'
});

Now, you can use $state.go like following:

$state.go('SignUpMember.OTPVerification', {
    customerid: 565,
    OTP: 9898
});

How to pass custom data using $state.go() in ui-router?

define state with param object:

$stateProvider
.state( 'edit', {
      url: '/api/:slug/edit',
      params: {
         params: null
       }
     //... 
})

create state.go() redirection

$state.go('edit',{slug:'slug-of-your-post-or-ID', params: {type: 'post'}});// or params: {type: 'page'}

back in stateProvider,

$stateProvider
.state( 'edit', {
      url: '/api/:slug/edit',
      params: {
         params: null
       }
     resolve:{
        resEditSnippet: ['$stateParams', function($stateParams){
 
              // check params.type value 
              if($stateParams.params.type=='post'){

               // do Logic something

              }else{

               // do Logic something else
                
              }
         
        }]
      }, 
})

I hope you get an idea about Simple Tips for Using UI-Router.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Dynemically HTML table from AJAX response using PHP

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *