Endless Loop RC9
by jamey777
HTML
<script src="http://code.angularjs.org/angular-1.0.0rc9.js"></script>
<div id="sg-header">
<h1>{{siteName}}</h1>
</div>
<ul id="sg-navigation" data-ng-controller="leftNavCtrl">
<li class="sg-nav-main" data-ng-repeat="topic in topics">
<h2>{{topic.text}}</h2>
<ul>
<li class="sg-nav-sub" data-ng-class="{active: location.path() == child.url}" data-ng-repeat="child in topic.children">
<a href="#{{child.url}}" >{{child.name}}</a>
</li>
</ul>
</li>
</ul>
<div id="sg-main" data-ng-view></div>
JavaScript
angular.module('styleguide', ['styleguide.service', 'styleguide.directive', 'styleguide.filter']).
run(['$rootScope', '$http', function ($rootScope, $http)
{
// This is effectively part of the main method initialization code
$rootScope.siteName = "Consumer Portal Style Guide";
$rootScope.pageTitle = "";
// Load in the navigation data
$http.get('js/data/topics.json').success(function (data)
{
$rootScope.topics = data;
});
} ]).
config(['$routeProvider', function ($routeProvider)
{
$routeProvider.
when('/', { template: 'partials/overview.html', controller: 'DefaultCtrl' }).
when('/overview', { template: 'partials/overview.html', controller: 'DefaultCtrl' }).
when('/resources', { template: 'partials/resources.html', controller: 'DefaultCtrl' }).
otherwise({ redirectto: '/overview' });
} ]);
function DefaultCtrl($scope, $rootScope, $route, $location, $routeParams)
{
if ($location.path() == "/")
{
$location.path('/overview');
return;
}
$scope.$route = $route;
$scope.$location = $location;
$scope.$routeParams = $routeParams;
//alert(company.name);
angular.forEach($rootScope.topics, function (navitem)
{
angular.forEach(navitem.children, function (childitem)
{
if (childitem.url == $location.path())
{
$scope.sectionTitle = navitem.text;
$scope.pageTitle = navitem.text + ": " + childitem.name;
$rootScope.pageTitle = navitem.text + " - " + childitem.name;
}
});
});
}
function leftNavCtrl($scope, $location)
{
$scope.location = $location;
}