0

I have a simple angular js ionic application. When I route for the first time to a view then the init function gets called. However any subsequent visits to the same view do not call the init function. I know this is probably called because cache is set to true by default on the app:

.state('app', {
    url: "/app",
    templateUrl: "templates/mainpage.html",
    controller : "appController"
  })

A simple controller:

angular.module('starter.controllers', []).controller('appController', function($scope) {
    var init = function() { alert("test"); }
});

My index.html:

<body ng-app="starter" class="ng-cloak">
    <ion-nav-view></ion-nav-view>
</body>

How can I make sure that init gets called each time the view is loaded?

Sonu Kapoor
  • 1,567
  • 3
  • 16
  • 34

1 Answers1

0

If you want to call a function everytime a view loads, take a look at ng-init.

Here's an example from Run a controller function whenever a view is opened/shown:

HTML:

<ion-nav-view ng-controller="indexController" name="other" ng-init="doSomething()"></ion-nav-view>
Community
  • 1
  • 1
MashterYoda
  • 118
  • 9