AngularJS: fn is not a function
After calling the function results
, I have an error: TypeError: fn is not a function
. Before making a call, everything works fine, $http.get
gets good data first. Any ideas how to fix this?
var app = angular.module("cowork", []);
app.config(function($interpolateProvider) {
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
});
app.controller("SearchDeskCtrl", ['$scope', '$http', function ($scope, $http) {
$scope.search = false;
$scope.city;
$http.get('/cowork/desks').success(function(data, status, headers, config) {
return $scope.results = data;
})
$scope.results = function(search) {
if (search){
$http.get('/cowork/desks_city', {city: $scope.city}).success(function(data, status, headers, config) {
search=false;
return data;
})}
}
}])
EDIT:
My goal is to get the results from the first $http.get
, and then, after calling the function, overwrite that data. Moreover, I need to pass one string parameter in the second call $http.get
(in the function) to pass the parameter city
, and then get it in request
(from the Django side).
source to share
After receiving response from $http.get('/cowork/desks')
ajax, your method $scope.results
gets overridden data
So when you call a method $scope.results
from $scope.results
within it, it will throw because it is no longer available in the context of the control scope.
TypeError: fn is not a function
The fix would be that you need to rename the results $http.get
to something else, for example $scope.result
would be fine.
code
$http.get('/cowork/desks').success(function(data, status, headers, config) {
$scope.result = data;
})
source to share