I am using ngRoute. index.html :
<body ng-app="mainApp" ng-controller="AboutController">
<div id="header">
<h1>Employee Gallery</h1>
</div>
<div id="leftpanel">
<!--a href="#/displayEmp" id="load">Display</a><br-->
<a href="#/display">Display</a><br>
Insert<br>
Delete
</div>
<!-- Angular dynamic content-->
<div ng-view id="section">
</div>
main.js :
var app = angular.module('mainApp',['ngRoute']);
app.config(function($routeProvider) {
$routeProvider
.when('/display', {
templateUrl: 'pages/display.html',
controller: 'DisplayController'
})
.when('/', {
templateUrl: 'pages/about.html',
controller: 'AboutController'
});
/*.otherwise({
redirectTo: '/'
});*/
});
app.controller('AboutController', function($scope) {
console.log("In AboutController");
$scope.msg = "This app performs CRUD operations";
});
If ng-app="mainApp" is specified in the body tag of index.html as shown, 'In AboutController' is printed twice. If ng-app="mainApp" is moved to then it is printed once, as should be. In both cases, output is the same. 1) But need to understand why the controller is executed twice in one case and once in the other. 2) In display.html, console.log is not getting printed within tag.