I have a menu that show different groups Name to which a user belongs . I prepared a template page so that when a user choose one of the menu's GROUPS , the template's fields change.
<li><a href="#"><i class="glyphicon glyphicon-folder-open"></i>Home </a></li>
<li><a data-toggle="collapse" ng-init="getAllGroupsofUser()"data-target="#groups">My Groups</a>
<ul id="groups" class="collapse">
<li ng-repeat="group in groupsofUser" ng-controller="groupsCTRL"><a
ng-click="openPage(group)">{{group.name}}</a>
</li>
</ul>
</li>
The Groups were successfully shown in the menu. I'm using ng-view and $routeProvider.
my $routeProvider
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'home.html',
controller:"MyController"
})
.when('/group/:groupname', {
templateUrl: "groupTemplate.html",
controller:"groupsCTRL"
}).
otherwise({
redirectTo: '/'
});
}]);
my controller
app.controller( 'groupsCTRL',[ '$scope', '$http' , '$location', '$routeParams' ,function($scope, $http,$location,$routeParams){
$scope.groupeName= $routeParams.groupname;
$scope.openPage = function(group) {
$scope.groupselected = group;
console.log( "group: "+$scope.groupselected.id);
location.href = "#/group/"+group.name;
}
}]);
my template
<div class="row" >
<h1 class="page-header">Groupe {{groupeName}} </h1>
</div>
<div class="row">
{{groupselected.id}}
</div>
my problem is that the groupeName is displayed , but the groupselected.id is only displayed in the console (because i used console.log( "group: "+$scope.groupselected.id);)
please help me , I need to know if the group was passed to the page because in the next step I'll need to show informations about that selected group .
$location.path("#/group/"+group.name);instead oflocation.href = "#/group/"+group.name;$scope.$apply()after it, will work for your case$scope.openPage = function(group) { $scope.groupselected = group; console.log( "group: "+$scope.groupselected.id); $location.path("/group/"+group.name); if(!$scope.$$phase) $scope.$apply() }