- You call
detectConnexionTest()
which begins an AJAX request and returns immediately - You call
detectConnexion()
with no parameter immediatly afterwards, which is guaranteed to return false even if your AJAX request had completed - When your AJAX call does return, you call
detectConnexion()
and do pass a value and it will return true or false, but you don't store that return value. - Since you're using
jQuery.ajax()
, angular does not know when your call returns so even if you did update a value on your scope properly your page would not update until angular went through another digest cycle.
What you should probably do is use $http
and set the scope value when the call returns:
function TestCtrl($scope, $http) {
function detectConnexion() {
$http.post("/connect").success(function(data, status, headers, config) {
$scope.online = "connected";
}).error(function(data, status, headers, config) {
$scope.online = "not connected";
}
}
detectConnexion();
}