繁体   English   中英

无法获取未定义或空引用的属性“ get”

[英]Unable to get property 'get' of undefined or null reference

我知道这可能真的很简单,但出现此错误

无法获取未定义或空引用的属性“ get”

当我从控制器调用API时

 rmdsController.$inject = ['$scope', 'rmds'];
function rmdsController($scope, rmds, $http) {

$scope.Calculate = function () {
        alert('made it');
        $("#spinner").show();


          $http.get('/api/rmd/calcRMDdist/')

          .success(function (data) {
              // Do stuff with data.
          })
          .catch(function (err) {
              // Log error somehow.
          })
          .finally(function () {
              // Hide loading spinner whether our call succeeded or failed.
              $scope.loading = false;
          });
    }

依赖注入是一种模式,通常在基础结构组件中使用,它可以确保一个特定组件不会直接创建对其他组件的引用。 每个组件都将接收对必需的其他组件(如助手,服务等)的引用,作为其构造函数的参数,而不是直接实例化。 在这种情况下:

rmdsController.$inject = ['$scope', 'rmds', '$http'];

这里,每当实例化此控制器时,Angular就将注入$ scope,rmds,$ http。

参考: http : //henriquat.re/basics-of-angular/services-dependency-injection/services-and-dependency-injection-in-angularjs.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM