Cannot read Array data

Asked

Viewed 37 times

0

I’m having problems in the code below is not able to read the value $Scope.ids[i]. id, follows code:

$scope.carregarEnderecos = function (id) {
    $scope.repeateEnderecos = [];
    $http.post(url_sistema + 'estabelecimento/listar_enderecos', {'id': id}).success(function (data, status, headers, config) {
        if (data !== '0') {
            $scope.repeateEnderecos = data;
            $scope.ids = [];
            for (var i = 0; i < data.length; i++){
                $scope.ids.push({'id':data[i].local_id});
            console.log($scope.ids);
            }
            $timeout(function () {
                $scope.telefonesEnderecos();
            }, 5000);
            $scope.existeendereco = true;
        } else {
            $scope.repeateEnderecos = 0;
            $scope.existeendereco = false;
        }
    }).error(function (data, status) { // called asynchronously if an error occurs
        alert(data);
    });
};

$scope.telefonesEnderecos = function () {
    $http.post(url_sistema + 'estabelecimento/telefones').success(function (data, status, headers, config) {
        if (data !== '0') {
            $scope.telefones_enderecos = data;


            for (var i = 0; i < data.length; i++)
            var tel = $scope.telefones_enderecos[i].fk_local_empresa;
             if ($scope.ids[i].id === tel) {
                console.log("deu");
            } else {
                console.log("nao deudeu");
            }
        }
    }).error(function (data, status) { // called asynchronously if an error occurs
        alert(data);
    });
};
  • Which function is called first? The "load Addons" or "Addons"? Because $Scope.ids is filled in the "load Addons" function. Another thing, its cycle "for" within the function "phonesEnderecos" does not have "{ ... }" braces so it will only include in the cycle outside the line below, the "if" will not enter, so its var "tel" will always be equal to the last position of the array "phones_addressees". If that’s so, then you don’t need the "for" cycle, just put var tel = $Scope.phones_addresses[data.length-1]. fk_local_company;

  • Thank you for commenting but I will no longer need to use this form of treatment because the tool that was being developed will no longer be used, development has been requested otherwise, but thank you for wanting to help, have a great day Filipe, thank you very much

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.