本文介绍了如何通过HTTP $,$通过要求范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.controller('Ctrlajax', ['$scope', 'version','$sce', '$resource', '$http',
  function ($scope, version,$sce,$resource,$http) {
    $scope.answer  = 'Ожидание ответа от сервера.....';
    require('ajax_module');
}])

ajax_module.js

define('ajax_module',['angular'],function($http){
   var path = './././data/' 
   $http.get(path+'res.php').success(function(data){
      debugger
      $scope.answer = data;
   });
})

错误:未捕获类型错误:未定义不是一个函数
如何通过$范围,$ HTTP?

Error:Uncaught TypeError: undefined is not a functionHow to pass $scope,$http?

推荐答案

我不知道你有什么做的。但既然你已经在你的控制器注入$ HTTP服务,你可以直接使用在控制器。

I am not sure what are you trying to do. But since you are already injected $http services in your controller, you can directly use is in controller.

     .controller('Ctrlajax', ['$scope', 'version','$sce', '$resource',
      '$http',function ($scope, version,$sce,$resource,$http) {
              $scope.answer  = 'Ожидание ответа от сервера.....';
              $http.get(path+'res.php').success(function(data){
                $scope.answer = data;
              });

       }])

如果您想逻辑分开,使用自定义的服务,而不是要求。然后,注入的服务,您的控制器来使用它。

If you want to separate the logic, use custom services instead of require. Then inject the services to your controller to use it.

这篇关于如何通过HTTP $,$通过要求范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:39