How to $state.go() in Angularjs?

0
()

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
Read Also:  Concatenation string and Class in VueJS

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
       }
     //... 
})

Free Live Chat for Any Issue

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
                
              }
         
        }]
      }, 
})

Download

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:  VueJS Trim String - VueJS Trim LTrim and RTrim Functions

How useful was this post?

Click on a star to rate it!