john323
john323

Reputation: 11

AngularJS ng-if does not work

In the controller, I have this

var onComplete = function(response)
{
        $scope.reportList = response.data;      
        $log.info($scope.reportList);                       
};

In the HTML, reportList is a JSON like this {packageType=1, salary=12900 }. ReportList is not an array {{ reportList.packageTypeId }} return 1

The issue is with ng-if div

<div class="exceptionProcedure" ng-if=" reportList.packageType == 1"> 

<a> display package 1 </a>

when I tried this, it still does not work

<div class="exceptionProcedure" ng-if=" {{reportList.packageType}} == 1">

 <a> display package 1 </a>

Any ideas?

Upvotes: 1

Views: 4649

Answers (1)

Tyler
Tyler

Reputation: 11499

You need to define reportList.packageType on the initial page load so that it links between your controller and view:

$scope.reportList = {}
var onComplete = function(response) {
    $scope.reportList = response.data;
    $log.info($scope.reportList);
};

This way, you'll only have one version that is shared between controller and view. The way you're doing it now creates two separate versions.

Upvotes: 1

Related Questions