este es mi codigo
$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; }); };pero recibe un error
TypeError: $scope.GetLocatoinByCountry no es una función
como solucionar esto
Mueva la función de llamada debajo de la asignación:
$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 hereTypeError: $scope.GetLocatoinByCountry no es una función
El error lo dice todo.
El problema era que estaba llamando a la función donde no existía en el $scope y estaba asignando la función al $scope más adelante.
Creo que cuando usa Angular 1 puede usar $http o $resource para llamar a la API.
En su caso: mueva la línea $scope.GetLocatoinByCountry(); de arriba hacia abajo puede hacer que funcione.