我想在我的自定义过滤器上注入$ http以在我的视图上使用它:
angular.module('demo').filter('quesByID',['$http', function() {
var input="";
return function(input) {
$http.get("http://localhost:3003/api/quiz/"+input).then(function(reponse){
input=reponse.data;
});
return input;
}
}]);
我有错误的错误,即$ http未定义
angular.js:13920 ReferenceError: $http is not defined
at getQuestionById.js:4
at fn (eval at compile (angular.js:14817), <anonymous>:4:198)
at regularInterceptedExpression (angular.js:16043)
at expressionInputWatch (angular.js:15948)
at Scope.$digest (angular.js:17515)
at Scope.$apply (angular.js:17790)
at done (angular.js:11831)
at completeRequest (angular.js:12033)
at XMLHttpRequest.requestLoaded (angular.js:11966)
我应该在哪里注入" $ http"依赖性?
您注射了dependency
,但在函数中不用用作argument
不要为此使用过滤器,您可以在控制器中写代码
angular.module('demo').controller('controller',['$http', function($http) {
$scope.data;
$scope.getData = function(input) {
$http.get("http://localhost:3003/api/quiz/"+input).then(function(reponse){
$scope.data = reponse.data;
});
}
}]);