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
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.
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.