Silk13
Silk13

Reputation: 57

Angularjs ng-show isn't working

Why isn't my container showing when I set selectedManager via an ng-click?

HTML:

<tr ng-repeat="manager in allManagers" ng-click="openDetails(manager)">
<div class="container" ng-show="selectedManager">

JS:

$scope.selectedManager;
$scope.openDetails = function(item) {
  selectedManager = item;
  console.log(selectedManager);
}

Console.log prints the object successfully?

Upvotes: 0

Views: 68

Answers (2)

Varun Sukheja
Varun Sukheja

Reputation: 6516

This is so because in your code:

$scope.selectedManager;
$scope.openDetails = function(item){
selectedManager=item;
console.log(selectedManager);
}

You are assigning value to selectedManager, which is a local variable and not scope variable $scope.selectedManager

To make it work you either use $scope.selectedManager in place of selectedManager

OR

assign $scope.selectedManager=item directly

local variables are not accessible in HTML, only scope variable are.

Upvotes: 3

karaxuna
karaxuna

Reputation: 26930

You shall modify $scope.selectedManager property:

$scope.openDetails = function (item) {
    $scope.selectedManager = item;
    console.log(selectedManager);
}; 

Upvotes: 1

Related Questions