We help IT Professionals succeed at work.

mainData in AngularJS

Tom Knowlton
Tom Knowlton asked
on
 <tr ng-hide="mainData.selectedTrade.ID === '4' || mainData.selectedTrade.ID === '5'">

Open in new window


Does mainData have some special meaning in angular?

I don't see it "declared" anywhere.
Comment
Watch Question

Manager / Solutions Architect
Commented:
No, it doesn't.
Does that <tr> ever disappear?

mainData is a scope variable and is either missing which in that case won't do anything, or is being set in the HTML or in one controller.
Be aware that scope inheritance exists in AngularJS so this scope variable may be coming from a higher level controller.
Tom KnowltonWeb developer

Author

Commented:
It was just an example from the code -- I've not tested it to see if it works or doesn't.

Based on what I see happening elsewhere -- it seems to be missing.  A global search through my source does not show it listed as other scope variables seem to be:

onlineApp.controller('confirmationReportController', ['$scope', '$rootScope', '$sce','$http', function ($scope, $rootScope, $sce, $http) {
 
 Perhaps the developer who began writing that portion intended to pass it in for injection and just hasn't yet.  He's offsite but I'll contact him about this.

So the fix would be:

onlineApp.controller('confirmationReportController', ['$scope', '$rootScope', '$sce','$http', '$mainData', function ($scope, $rootScope, $sce, $http, $mainData) {
 

Right?

Thanks!

Tom
Tom KnowltonWeb developer

Author

Commented:
Great job.
Alexandre SimõesManager / Solutions Architect

Commented:
Actually the fix is not that and it's almost certain to throw an $injector error.

The code expects this to exist: mainData.selectedTrade.ID
So you need a mainData variable in the scope that had a property selectedTrade that in turn as a property ID.
Something like:
$scope.mainData = {
  selectedTrade : {
    ID: '4'
  }
};

Open in new window

With this code in your controller the <tr> element should disappear.
Tom KnowltonWeb developer

Author

Commented:
Thank you ... I'll make sure this happens.