mainData in AngularJS

 <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.
Tom KnowltonWeb developerAsked:
Who is Participating?
Alexandre SimõesManager / Technology SpecialistCommented:
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 developerAuthor 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) {



Tom KnowltonWeb developerAuthor Commented:
Great job.
Alexandre SimõesManager / Technology SpecialistCommented:
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 developerAuthor Commented:
Thank you ... I'll make sure this happens.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.