I have a nav that looks something like this:
<div class="collapse navbar-collapse" id="admin-side-nav" ng-controller="AdminNav">
<ul class="nav nav-pills nav-stacked">
<li><a href="/admin/leaderboard/{{gameId}}">Leaderboard</a></li>
<li><a href="/admin/newsFeed/{{gameId}}">News Feed</a></li>
</ul>
</div>
I am then using routes which load a template and with an ajax request to get data to put in the template. The returned request has an id in it that I would like to bind to gameId
, but I can't figure out how it is done.
Here is the javascript to do this:
var console = angular.module('Console', ["ngRoute", "highcharts-ng"]);
console.config(function($routeProvider, $locationProvider){
$routeProvider.when('/admin/:gameid', {
templateUrl: 'admin/game.html',
controller: 'Game'
});
}).controller("Game", function($scope, $http){
$http.get("http://admin.gmserver.net/mypage").success(function(data){
$scope.games = data;
$scope.gameId = data._id;
});
}).controller("AdminNav", function($scope, $location){
$scope.isActive = function(viewLocation){
return viewLocation === $location.path();
};
});
I would like to bind this line from the Game
controller $scope.gameId = data._id;
to the value in the AdminNav
controller. How can I pass the data from the Game
controller to the AdminNav
controller?