I know that the ng-if directive creates a new child scope and I would like to know HOW and IF it is possible to play a ng-if into an other one.
For now I can't see any icons. I've tried ng-hide, but I saw the two icons in the same time, impossible to fix that problem...I also tried ng-show, but with the same results as ng-if.
Set() function returns true or false, it's working because I can see the result in the console.
Any ideas ?
$scope.set = function($r)
{
firebase.database().ref('events/'+$r.selfID).once("value").then(function(snapshot)
{
var nbPerson = snapshot.val().nbPerson;
var varPerson = snapshot.val().varPerson;
//console.log("nbPerson :", nbPerson);
//console.log("varPerson", varPerson);
if(nbPerson === varPerson)
{
//console.log("true");
return true;
}
else
{
//console.log("false");
return false;
}
});
};
<button ng-if ="give(f) === false" class="badge badge-positive" ng-click="joinEvent(e)">
<span ng-if ="set(r) === true">
<ion-icon class="ion-person-add give-var"></ion-icon>
</span>
<span ng-if ="set(r) === false">
<ion-icon class="ion-person-add var"></ion-icon>
</span>
</button>
EDIT :
I added the set() function, $r is a record from a Firebase DB, it has a "selfID" variable with his record ID.
I'm sure that give() function is working, because I have an other button running with the ng-if="give(f) === true".
This entire code is working on the same controller.
EDIT 2 : (new snippet)
EDIT 3 : (add $q in dependency)
function ($scope, $rootScope, $q, $stateParams, $firebase, $firebaseArray, $state, $ionicPopup) {
$scope.set = function($r)
{
$scope.varPerson = "";
$scope.nbPerson = "";
var basePromise = firebase.database().ref('events/'+$r.selfID).once("value");
$q.when(basePromise).then(function(snapshot)
{
$scope.nbPerson = snapshot.val().nbPerson;
$scope.varPerson = snapshot.val().varPerson;
if($scope.nbPerson === $scope.varPerson)
{
return true;
}
else
{
return false;
}
});
}
};
EDIT 4 : (Finally)
Ok, I wasn't able to cope with the synchronous problems, so I simply add a test inside the two ng-if, so without the set() function.
Thanks a lot for those who helped me, and especially @georgeawg for his expertise !
<span ng-if ="r.nbPerson === r.varPerson">
<ion-icon class="ion-person-add give-var"></ion-icon>
</span>
<span ng-if ="r.nbPerson > r.varPerson">
<ion-icon class="ion-person-add var"></ion-icon>
</span>