Reload controller in ionic

I have a webview template which loads data from a link. So, if I have to load a separate webview I use the same template and controller and change the link. It works fine for most cases. However, if I try to load a different webview from the current one it does not work. The reason is that the controller is not triggered again as we are loading the same view. I tried navigating a different page and then moving to webview template, however the result is the same the controller is not initialised. How can I trigger the controller or have the controller reload?

I tried setting cache to false globally and setting reload to true however it still does not reload the controller.
Here is how my code looks

.state('webView', {
		    url: '/webView',
            cache: false,
		    templateUrl: 'templates/webView.html',
		    controller: 'WebViewCtrl',
            reload: true

I have also set


However, my controller still refuses to reload. Any ideas on what am missing?

Finally ended up using state transition mentioned in this link - However, I still feel the reload and cache attributes should have done the trick too. Not sure why they dint work out for me

Hi there

I got around this issue by placing all the code I need to execute on each refresh inside of the “enter” event listener, like so:

$scope.$on('$ionicView.enter', function() {
//Do whatever you need to here like make a call to a factory etc

Enter is triggered irrespective of whether or not the view has been cached.

Hope that helps :smile:

Hey hi there,

Am glad you took time to take a look at this. However, enter event is not triggered if the view is cached. As I mentioned the controller is not called at all so none of the events get fired.
Finally ended up using state transition mentioned in this link -

$state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true });

This did the trick for me and reloaded my view and the controller.