I previously thought that the controller script would only be executed once, when my single page application is loaded.
Now I see that every time I change a view my controller script executes again. I can tell because i had a couple of statements in the script that are not nested in functions. I want them to happen only when the app is first loaded, but they are running when I change views.
The views are configured in my app.js with module.config:
myModule.config(function ($routeProvider) {
$routeProvider
.when('/search', {
templateUrl: 'views/search.html',
controller: 'searchCtrl'
})
.when...
So, is it normal for the controller script to run when the view changes? Or should I be searching for something I have configured wrong?