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.
我知道ng-if指令创建了一个新的子范围,我想知道如何以及如果可以将ng-if转换为另一个。
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.
Promises returned by the firebase API are not integrated with the AngularJS framework.
firebase API返回的Promise未与AngularJS框架集成。
Use $q.when to create an AngularJS promise from a firebase promise:
使用$ q.when从firebase承诺创建AngularJS承诺:
var basePromise = firebase.database().ref('events/'+$r.selfID).once("value");
$q.when(basePromise).then(function(snapshot)
{
//.then block code
});
AngularJS modifies the normal Javascript flow by providing its own event processing loop. This splits the Javascript into classical and AngularJS execution context. Only operations which are applied in the AngularJS execution context will benefit from AngularJS data-binding, exception handling, property watching, etc.
$scope.set = function($r) {
var value = set($r);
console.log(value);
return value;
});
//BUGGY function
function set($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;
}
});
};
By using this simple debugging technique, you will quickly understand the problem.
通过使用这种简单的调试技术,您将很快了解问题。
the result of my set() function is unreachable... :( Is my new function (Edit 3), correct ?
我的set()函数的结果是无法访问... :(是我的新功能(编辑3),对吗?
The return statements inside .then blocks do not return values to the parent function. The code inside .then blocks execute asynchronously after the parent function completes.
Javascript is single-threaded. Functions complete immediately. They can not return values created in .then blocks. They can only return values that are produced immediately and synchronously or they can return pending promises that later asynchronously resolve to some value.
The console log for "Part4" doesn't have to wait for the data to come back from the server. It executes immediately after the XHR starts. The console log for "Part3" is inside a success handler function that is held by the $q service and invoked after data has arrived from the server and the XHR completes.