I'm using the routing feature of AngularJS. Furthermore I want only on controller for all templates.
In my controller angularJsController I have an initfunction, which should only be executed at the first time the controller gets executed and when I explicitly call the function. But I don't wan't that the init function will be executed each time the routing loads another template.
How can I achieve the desired behaviour?
var app = angular.module("angularJsApplication", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/overview", {
templateUrl : "overview.html",
controller : "angularJsController"
.when("/settings", {
templateUrl : "settings.html",
controller : "angularJsController"
...
});
app.controller("angularJsController", function ($scope, $location, $http) {
$scope.init = function() {
//do stuff
};
}