Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
How to call to angular ajax function from angular controller

this is my code

$scope.GetLocatoinByCountry();

$scope.GetLocatoinByCountry = function () {
        $http({
            method: 'POST',
            url: '/JobPost/GetLocationByCountry',
            data: { countryId: $scope.draftJobPost.countryID }
        }).then(function successCallback(response) {
            var loc = response.data;
            $scope.locations = response.data;
        }, function errorCallback(response) {
            var error = response;
        });
    };

but get an error

TypeError: $scope.GetLocatoinByCountry is not a function

how to solve this

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Move the calling function below the assignation:

$scope.GetLocatoinByCountry = function() {
  $http({
    method: 'POST',
    url: '/JobPost/GetLocationByCountry',
    data: {
      countryId: $scope.draftJobPost.countryID
    }
  }).then(function successCallback(response) {
    var loc = response.data;
    $scope.locations = response.data;
  }, function errorCallback(response) {
    var error = response;
  });
};

$scope.GetLocatoinByCountry(); // move it here

TypeError: $scope.GetLocatoinByCountry is not a function

The error says everything.

The issue was you were calling the function where it wasn't existed in the $scope and you were assigning the function to the $scope later on.

about 4 years ago · Santiago Trujillo Relatório

0

I think when using Angular 1 you can use $http or $resouce for calling API.

In your case: move the line $scope.GetLocatoinByCountry(); from above to below can make it work.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda