Reputation: 408
This problem makes me a huge headache - I don't know why, but in my application i have two $rootScope, with $id "001" and "003" (each has separated variables). I checked ng-app occurrence and it's only once at main page.
Anyone have any idea why it is like that ?
Angular 1.1.5 (same on 1.0.7)
Index.cshtml
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8" />
<title></title>
<meta name="viewport" content="width=device-width" />
@Cassette.Views.Bundles.RenderStylesheets()
</head>
<body id="body" class="container-fluid" ng-app="app">
<div ng-view ng-cloak class="row-fluid">
</div>
@Cassette.Views.Bundles.RenderScripts()
</body>
</html>
App.js:
var app = angular.module('app', ['ngResource', 'ngCookies'])
.config(['$locationProvider', '$routeProvider', '$httpProvider', function ($locationProvider, $routeProvider, $httpProvider) {
var access = RoutingConfig.accessLevels;
$locationProvider.html5Mode(false);
$routeProvider
.when('/',
{
redirectTo: '/Entries'
})
.when('/Login',
{
templateUrl: 'Views/Security/Login',
controller: 'LoginController',
access: access.anonymous
})
.when('/Entries',
{
templateUrl: 'Views/Entry/List',
controller: 'EntryListController',
access: access.user
});
}])
.run(['$rootScope', '$location', 'SecurityService', function ($rootScope, $location, SecurityService) {
$rootScope.$on("$locationChangeStart", function (event, next, current) {
$rootScope.error = null;
if (!SecurityService.Authorize(next.access ? next.access : RoutingConfig.accessLevels.public)) {
if (SecurityService.IsLoggedIn()) {
$location.path('/');
}
else {
$location.path('/Login');
}
}
});
}]);
Just to make sure both templates are empty. $rootScope is changing on second $locationChangeStart :(
Upvotes: 0
Views: 831
Reputation: 6992
Haven't been able to reproduce your problem - but we've seen similar trouble with double controllers / scope because we accidentally specified the controller twice - once in the routing tables ($routeProvider.when(..., controller="xyzCtrl", templateUrl="xyz.html"
) and again in my template (data-ng-controller="xyzCtrl"
). Removing either one of them fixed the problem. Hope this is a clue in the right direction.
Upvotes: 3