So I have a dataservice function that with an api call get's the type of the logged in account(admin and customer are two of them).
If a customer is logged in, five columns shouldn't be shown in a table I have with data. So I use an ng-if which doesn't seem to work.
this.hideSensitiveData = true;
function updateHideSensitiveDataFlag() {
return dataservice
.getUserType()
.then(function (data) {
var userType = data;
this.hideSensitiveData = userType === "Customer";
});
}
And one of the coulmns(in thead and tbody):
<th sort by="'pumpPressure'" order="order" reverse="reverse" ng-if="this.hideSensitiveData">{{ 'PumpPressure' | translate}}</th>
<td ng-if="this.hideSensitiveData">{{sequence.pumpPressure.toFixed(1)}}</td>
"data" here will be the account type. So if I understand ng-if correctly the element will be removed in the DOM if the expression evaluates to false. So the value will be true here on this.hideSensitiveData if I'm logged in as a customer. Still it removes the columns, which obviously confuses me since it should only remove it if it's false.
Thanks in advance!
EDIT: here is the dataservice funtion if it helps:
function getUserType() {
return $http.get('/api/v2/user/getUserType/')
.then(function (xhr) {
logger.info('userType loaded: ', xhr);
var userType = xhr.data;
return userType;
})
.catch(function (message) {
logger.error('XHR Failed for userType', message);
return $q.reject(message);
});
}
EDIT2: In response to the duplicate flag. I actually have var self = this;
at the top of the controller... Is that why everyone got so confused?
So I use self.hideSensitiveData instead of this.hideSensitiveData. Didn't know it mattered.