[英]AngularJS: fn is not a function
調用函數results
我有一個錯誤: TypeError: fn is not a function
。 在調用之前,一切正常,首先$http.get
獲得良好的數據。 任何想法如何解決它?
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;
})}
}
}])
編輯:我的觀點是從第一個$http.get
獲取結果,然后在調用函數后覆蓋這些數據。 此外,我需要在第二個$http.get
調用(在函數中)傳遞一個字符串參數來傳遞city
參數,然后在request
接收它(來自Django端)。
從$http.get('/cowork/desks')
獲取響應ajax后,您的$scope.results
方法被數據覆蓋
因此,當您調用$scope.results
時,它將拋出,因為$scope.results
在控制器范圍上下文中不再可用。
TypeError:fn不是函數
修復將需要重命名的結果$http.get
別的東西一樣$scope.result
將被罰款。
碼
$http.get('/cowork/desks').success(function(data, status, headers, config) {
$scope.result = data;
})
您將結果用作案例1中的var,並將案例2中的函數用作函數。
Case1: return $scope.results = data;
Case2: $scope.results = function(search) {
使用適當的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.