无法获得房产'得到'未定义或空引用

时间:2016-05-22 23:03:19

标签: angularjs asp.net-mvc angular-controller

我知道这可能很简单,但我收到此错误

无法获得财产'得到'未定义或空引用

当我从控制器拨打我的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;
          });
    }

1 个答案:

答案 0 :(得分:2)

依赖注入是一种模式,通常用于基础结构组件,并确保一个特定组件不直接创建对其他组件的引用。而不是直接实例化,每个组件都将接收对所需其他组件(如帮助程序,服务等)的引用作为其构造函数的参数。在你的情况下像这样:

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

这里,只要实例化这个控制器,$ scope就会注入$ scope,rmds,$ http。

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