I was having trouble with an ng-repeat, where values which I expected to be set are not.

So, I added a few lines of debug, showing some values in the HTML of my current view.

Given

<div ng-hide="campaignDataEmpty" ng-repeat="campaign in campaigns" ng-click="CampaignClicked($event, campaign.campaign_id)">

Can I debug by <p>{{campaign}}</p>, given that campaign is a loop control variable, rather than a $scope variable?

I originally wanted to debug a single field of the object campaign, so added
<p>{{campaign.campaign_id}}</p>, which displayed correctly. Then I wanted to see more fields, so added a <p>{{campaign}}</p>, without removing the previous statement.

What I find is that, no matter whether I

<p>{{campaign}}</p>
<p>{{campaign.campaign_id}}</p>

or

<p>{{campaign.campaign_id}}</p>
<p>{{campaign}}</p>

The first always displays correctly and the second always appears to be empty.

What am I doing wrongly?

share|improve this question
    
campaign is a $scope variable. But it's part of the sub-scope created by ng-repeat. Not part of your controller scope. Post a minimal complete example reproducing the problem. The code matters. – JB Nizet 6 mins ago
    
You should definitely be able to view your campaign variable if you're trying inside the repeater. Outside of it it wouldn't exist. – casraf 2 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.