samedi 17 décembre 2016

Angular Js- Why If condition is not running?

Hi I am trying to run this chunk of code where I am comparing two values but seems like the comparison is not working .

for (var i = 0; i <= $scope.subcats.length - 1; i++)
            {
                console.log($scope.subcategory_id);
                if ($scope.subcats[i].id === $scope.subcategory_id)
                {
                    console.log($scope.subcats[i].name);
                    $scope.subcat_selected_name = $scope.subcats[i].name;
                    alert($scope.subcat_selected_name);
                }
            }

where as $scope.subcategory_id has value 1 but it does not work. But if I write something like this if ($scope.subcats[i].id ===1) It does run.

Aucun commentaire:

Enregistrer un commentaire