why does the code return and not the value

$scope.profileThenEdit = { userEdit: function () { ref.child('users').child(ref.getAuth().uid).child('mailregister').once("value", function (snapshot) { return snapshot.child("edit").val() }); } }; $scope.$watch('profileThenEdit.userEdit', function (dataLoaded) { console.log(dataLoaded); //if (dataLoaded) { // $location.path('profile'); //} else { // $location.path('editprofile'); //} }); 

    1 answer 1

    Because the value of the profileThenEdit.userEdit property is tracked - this is a function property

    Thus, the function itself is displayed in the log, and not the result of its call.

    Well, pay attention to the fact that this function returns nothing

    • What needs to be done to change this? - David Kern
    • @DavidKern, it all depends on what you need to get in the end, at least you need to track not the function. Most likely there is no need to use $ watch here , but for a complete answer, you need, as I wrote in a comment to a previous deleted question, to add a minimal reproducible example , because now it is not known what is generally used and what should be the result - Grundy
    • when registering, I send the value 0, in the firebase then when I visit the site I want to get this value. and in if ask if 0 then go to the edit page if 1 then to profile but if itself is called faster than I receive the data - David Kern
    • @DavidKern, so I want a minimal reproducible example , the description is absolutely incomprehensible what is now, what additional libraries are used, etc. - Grundy
    • @DavidKern, I have several times given a link to a certificate where it is described what a minimal reproducible example is , you should read about it and still add it - Grundy