2016-06-28 87 views
-1

我想通過使用超時方法添加2000ms的延遲,但它不工作,如果我嘗試在cotroller內的函數(searchfunc)中調用它。它給出了錯誤:$超時不是一個函數。 控制器代碼:

var angularjsapp = angular.module('graphApp', ['ngAnimate', 'ui.bootstrap','ui.grid']); 

angularjsapp.controller('AccordionDemoCtrl', function($scope, $timeout) { 

    $scope.searchfunc = function(search_name,$timeout) { 
     WebSocketTest(search_name,keyword_type); 
     //$scope.loading = false; 
     $timeout(function() { 
      $scope.loading = false; 
     }, 2000); 

}); 

回答

2

你傳遞$timeout作爲參數傳遞給你的函數

$scope.searchfunc = function(search_name,*$timeout* 

這將使當你調用該函數,因爲你不一起傳遞它不確定的。刪除它將解決問題。

scope.searchfunc = function(search_name) 

您可以瞭解它是如何工作(關閉)here

1

您在內部函數重載$timeout
就忽略它:

$scope.searchfunc = function(search_name) { 

可能是你的意思是keyword_type第二個參數?
因爲現在看起來像undefined

$scope.searchfunc = function(search_name, keyword_type) {