0

I can use javascript functions like window.location().But can also use $state.go and $state.transitionTo methods of angularjs.But using the angularjs $state service, the state doesnt reload everytime.I need to reload the state everytime the app enters that state through the angular ui router and the view should also be updated everytime.Do i have to use the more native window.location method? Please this is important as the $state service methods are not reloading the state everytime I followed the link Reloading current state - refresh data .But the inherit:false property value in the transitionTo method is not reloading the state everytime on my app end.Maybe it has to do something with cache.

What i want to achieve is that after editing a form it will go the listing state and show the updated values in that state which i updated through the form.But in that state it is still showing the previous values.ie. the state is not reloading everytime and the values are not updating everytime

This is the controller code:

EditUser.workat(company_form,$scope.userId).then(function(response){
            console.log(response);
            $scope.hide();
            if(response.data.is_success) {
                    $scope.company_form = response.data.company_address_info;
                    //$state.go('about', {user_id: $scope.userId}, {reload: true});
                    $state.transitionTo('about', {user_id: $scope.userId}, {
                        reload: true,
                        inherit: false,
                        notify: true
                    });
            }else{

                $ionicPopup.alert({
                  title: 'Error',
                  content: response.data.message
                });

            }
        });
Community
  • 1
  • 1
WebInsight
  • 307
  • 2
  • 20
  • Best way is not to `reload` it ? Why do you want to do it ? – Rayon Apr 18 '16 at 07:27
  • Possible duplicate of [Reloading current state - refresh data](http://stackoverflow.com/questions/21714655/reloading-current-state-refresh-data) – Rayon Apr 18 '16 at 07:27
  • @rayon it is not duplicate as the transitionTo is not reloading the state 'everytime' on my app – WebInsight Apr 18 '16 at 07:28
  • @rayon Please see why i want to do it.I have edited my question to show the flow and why i want to update the state.Basically the state is data listing.In another state where the update form is present ,after updating the app goes again to the listing state.But the values are not updated with the form updating the values – WebInsight Apr 18 '16 at 07:47

2 Answers2

2

In html :

<a ui-sref="home" ui-sref-opts="{reload: true}">Home</a>

In Javascript

$state.go('name', {reload:true});

https://github.com/angular-ui/ui-router/wiki/Quick-Reference

Walfrat
  • 5,363
  • 1
  • 16
  • 35
  • set the values of reload to true.Also set the value of inherit property to false in transitionTo method.But still not reloading everytime – WebInsight Apr 18 '16 at 07:48
  • What do you call precisely **not refreshing** ? The controller did not get executed again ? Or does some data are not refreshed ? If controller is executed again and you have a problem with your data, then checl your own code, it won't be a ui-router problem. – Walfrat Apr 18 '16 at 07:54
  • I checked what you said and found out that actually the controller is not getting executed.So what should i do? – WebInsight Apr 18 '16 at 07:55
  • Try update to the last version 0.x if you're not in, i know there was a bug at a moment with reloading, this may be fixed. – Walfrat Apr 18 '16 at 07:59
  • Lets say it is a bug then what do i try? The window.location method? – WebInsight Apr 18 '16 at 08:04
  • i guess so, the strange thing is that i already use the reload attributes and it worked for me. And even if i don't set it, my controller get reexecuted every time. Can you provide detail about your state hierarchy ? – Walfrat Apr 18 '16 at 08:06
  • This is the data listing state http://localhost:8100/#/about/26;This is the update form state:http://localhost:8100/#/edit_profile_workat/26.After submiting the form in the update form state the app goes to the data listing state but doesnt update the data.Clicking update button in the data listing state goes to the update form state with the id. – WebInsight Apr 18 '16 at 08:07
  • This is exaclty what i have and it works for me even without reload set. I have a home.admin.object.search and home.admin.object.modify state. When i modify object and use a $state.go to my search state it works perfectly fine. Can you try to st up your states so they have a common parent and they're 'brothers' ? This sound kind tricky but this is the only difference i have with you. Last question, can you post your listing state definition and the controller code, just to check some things in it. – Walfrat Apr 18 '16 at 08:14
  • Ok i will try your advice and notify you back. – WebInsight Apr 18 '16 at 09:01
  • This is the state definition: `.state('about', { url: '/about/:user_id', templateUrl: 'templates/user_about.html', controller: 'AboutCtrl' })` and the controller code is given in the question – WebInsight Apr 18 '16 at 09:04
  • By the way there is something strange in your code : why do you have $scope.company_form = response.data.company_address_info; when you change of state right after ? – Walfrat Apr 18 '16 at 09:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109410/discussion-between-debojyoti-and-walfrat). – WebInsight Apr 18 '16 at 09:07
0

Actually I'm taking a guess here because there are not enough infos regarding what you want to achieve.

The native ui-router reload method is: $state.reload()

or: $state.go('YOUR.STATE', {reload:true}); That will reload your current state. Still though this is seems not a god approach (to reload the state every time but still there are no enough infos related with you goal and source.

Vassilis Pits
  • 3,788
  • 4
  • 33
  • 48