错误:undefined不是对象(评估' $ http.get')

时间:2017-01-29 18:50:22

标签: angularjs

我有一个像这样的JSON文件:

{

  "variantA": {
    "sumInsuredThirty": [
      {
        "DAYFROM": 1,
        "DAYTO": 3,
        "TARIF": 2
      },
      {
        "DAYFROM": 4,
        "DAYTO": 5,
        "TARIF": 2
      },
      {
        "DAYFROM": 6,
        "DAYTO": 8,
        "TARIF": 4
      },
      {
        "DAYFROM": 9,
        "DAYTO": 10,
        "TARIF": 5
      },
      {
        "DAYFROM": 11,
        "DAYTO": 12,
        "TARIF": 5
      },
      {
        "DAYFROM": 13,
        "DAYTO": 17,
        "TARIF": 8
      },
      {
        "DAYFROM": 18,
        "DAYTO": 21,
        "TARIF": 9
      },
      {
        "DAYFROM": 22,
        "DAYTO": 25,
        "TARIF": 10
      },
      {
        "DAYFROM": 26,
        "DAYTO": 29,
        "TARIF": 12
      },
      {
        "DAYFROM": 30,
        "DAYTO": 31,
        "TARIF": 13
      },
      {
        "DAYFROM": 32,
        "DAYTO": 35,
        "TARIF": 14
      },
      {
        "DAYFROM": 36,
        "DAYTO": 40,
        "TARIF": 16
      },
      {
        "DAYFROM": 41,
        "DAYTO": 44,
        "TARIF": 18
      },
      {
        "DAYFROM": 45,
        "DAYTO": 50,
        "TARIF": 19
      },
      {
        "DAYFROM": 51,
        "DAYTO": 56,
        "TARIF": 22
      },
      {
        "DAYFROM": 57,
        "DAYTO": 60,
        "TARIF": 23
      },
      {
        "DAYFROM": 61,
        "DAYTO": 70,
        "TARIF": 26
      },
      {
        "DAYFROM": 71,
        "DAYTO": 80,
        "TARIF": 28
      },
      {
        "DAYFROM": 81,
        "DAYTO": 90,
        "TARIF": 32
      },
      {
        "DAYFROM": 91,
        "DAYTO": 120,
        "TARIF": 37
      },
      {
        "DAYFROM": 121,
        "DAYTO": 150,
        "TARIF": 44
      },
      {
        "DAYFROM": 151,
        "DAYTO": 180,
        "TARIF": 50
      },
      {
        "DAYFROM": 181,
        "DAYTO": 210,
        "TARIF": 55
      },
      {
        "DAYFROM": 211,
        "DAYTO": 240,
        "TARIF": 60
      },
      {
        "DAYFROM": 241,
        "DAYTO": 270,
        "TARIF": 64
      },
      {
        "DAYFROM": 271,
        "DAYTO": 99999999,
        "TARIF": 73
      }
    ],
    "sumInsured.Fifty": [
      {
        "DAYFROM": 1,
        "DAYTO": 3,
        "TARIF": 2
      },
      {
        "DAYFROM": 4,
        "DAYTO": 5,
        "TARIF": 3
      },
      {
        "DAYFROM": 6,
        "DAYTO": 8,
        "TARIF": 4
      },
      {
        "DAYFROM": 9,
        "DAYTO": 10,
        "TARIF": 5
      },
      {
        "DAYFROM": 11,
        "DAYTO": 12,
        "TARIF": 7
      },
      {
        "DAYFROM": 13,
        "DAYTO": 17,
        "TARIF": 9
      },
      {
        "DAYFROM": 18,
        "DAYTO": 21,
        "TARIF": 11
      },
      {
        "DAYFROM": 22,
        "DAYTO": 25,
        "TARIF": 13
      },
      {
        "DAYFROM": 26,
        "DAYTO": 29,

        "TARIF": 15
      },
      {
        "DAYFROM": 30,
        "DAYTO": 31,
        "TARIF": 16
      },
      {
        "DAYFROM": 32,
        "DAYTO": 35,
        "TARIF": 17
      },
      {
        "DAYFROM": 36,
        "DAYTO": 40,
        "TARIF": 19
      },
      {
        "DAYFROM": 41,
        "DAYTO": 44,
        "TARIF": 22
      },
      {
        "DAYFROM": 45,
        "DAYTO": 50,
        "TARIF": 23
      },
      {
        "DAYFROM": 51,
        "DAYTO": 56,
        "TARIF": 27
      },
      {
        "DAYFROM": 57,
        "DAYTO": 60,
        "TARIF": 28
      },
      {
        "DAYFROM": 61,
        "DAYTO": 70,
        "TARIF": 31
      },
      {
        "DAYFROM": 71,
        "DAYTO": 80,
        "TARIF": 35
      },
      {
        "DAYFROM": 81,
        "DAYTO": 90,
        "TARIF": 39
      },
      {
        "DAYFROM": 91,
        "DAYTO": 120,
        "TARIF": 45
      },
      {
        "DAYFROM": 121,
        "DAYTO": 150,
        "TARIF": 54
      },
      {
        "DAYFROM": 151,
        "DAYTO": 180,
        "TARIF": 61
      },
      {
        "DAYFROM": 181,
        "DAYTO": 210,
        "TARIF": 68
      },
      {
        "DAYFROM": 211,
        "DAYTO": 240,
        "TARIF": 73
      },
      {
        "DAYFROM": 241,
        "DAYTO": 270,
        "TARIF": 77
      },
      {
        "DAYFROM": 271,
        "DAYTO": 99999999,
        "TARIF": 89
      }
    ],
    "sumInsuredSeventy": [
      {
        "DAYFROM": 1,
        "DAYTO": 3,
        "TARIF": 2
      },
      {
        "DAYFROM": 4,
        "DAYTO": 5,
        "TARIF": 3
      },
      {
        "DAYFROM": 6,
        "DAYTO": 8,
        "TARIF": 5
      },
      {
        "DAYFROM": 9,
        "DAYTO": 10,
        "TARIF": 6
      },
      {
        "DAYFROM": 11,
        "DAYTO": 12,
        "TARIF": 8
      },
      {
        "DAYFROM": 13,
        "DAYTO": 17,
        "TARIF": 11
      },
      {
        "DAYFROM": 18,
        "DAYTO": 21,
        "TARIF": 12
      },
      {
        "DAYFROM": 22,
        "DAYTO": 25,
        "TARIF": 15
      },
      {
        "DAYFROM": 26,
        "DAYTO": 29,
        "TARIF": 17
      },
      {
        "DAYFROM": 30,
        "DAYTO": 31,
        "TARIF": 19
      },
      {
        "DAYFROM": 32,
        "DAYTO": 35,
        "TARIF": 20
      },
      {
        "DAYFROM": 36,
        "DAYTO": 40,
        "TARIF": 23
      },
      {
        "DAYFROM": 41,
        "DAYTO": 44,
        "TARIF": 25
      },
      {
        "DAYFROM": 45,
        "DAYTO": 50,
        "TARIF": 27
      },
      {
        "DAYFROM": 51,
        "DAYTO": 56,
        "TARIF": 31
      },
      {
        "DAYFROM": 57,
        "DAYTO": 60,
        "TARIF": 33
      },
      {
        "DAYFROM": 61,
        "DAYTO": 70,
        "TARIF": 37
      },
      {
        "DAYFROM": 71,
        "DAYTO": 80,
        "TARIF": 41
      },
      {
        "DAYFROM": 81,
        "DAYTO": 90,
        "TARIF": 45
      },
      {
        "DAYFROM": 91,
        "DAYTO": 120,
        "TARIF": 53
      },
      {
        "DAYFROM": 121,
        "DAYTO": 150,
        "TARIF": 63
      },
      {
        "DAYFROM": 151,
        "DAYTO": 180,
        "TARIF": 72
      },
      {
        "DAYFROM": 181,
        "DAYTO": 210,
        "TARIF": 79
      },
      {
        "DAYFROM": 211,
        "DAYTO": 240,
        "TARIF": 85
      },
      {
        "DAYFROM": 241,
        "DAYTO": 270,
        "TARIF": 91
      },
      {
        "DAYFROM": 271,
        "DAYTO": 99999999,
        "TARIF": 104
      }
    ],
    "sumInsuredHundred": [
      {
        "DAYFROM": 1,
        "DAYTO": 3,
        "TARIF": 2
      },
      {
        "DAYFROM": 4,
        "DAYTO": 5,
        "TARIF": 4
      },
      {
        "DAYFROM": 6,
        "DAYTO": 8,
        "TARIF": 6
      },
      {
        "DAYFROM": 9,
        "DAYTO": 10,
        "TARIF": 7
      },
      {
        "DAYFROM": 11,
        "DAYTO": 12,
        "TARIF": 8
      },
      {
        "DAYFROM": 13,
        "DAYTO": 17,
        "TARIF": 12
      },
      {
        "DAYFROM": 18,
        "DAYTO": 21,
        "TARIF": 14
      },
      {
        "DAYFROM": 22,
        "DAYTO": 25,
        "TARIF": 16
      },
      {
        "DAYFROM": 26,
        "DAYTO": 29,
        "TARIF": 19
      },
      {
        "DAYFROM": 30,
        "DAYTO": 31,
        "TARIF": 20
      },
      {
        "DAYFROM": 32,
        "DAYTO": 35,
        "TARIF": 22
      },
      {
        "DAYFROM": 36,
        "DAYTO": 40,
        "TARIF": 25
      },
      {
        "DAYFROM": 41,
        "DAYTO": 44,
        "TARIF": 27
      },
      {
        "DAYFROM": 45,
        "DAYTO": 50,
        "TARIF": 30
      },
      {
        "DAYFROM": 51,
        "DAYTO": 56,
        "TARIF": 34
      },
      {
        "DAYFROM": 57,
        "DAYTO": 60,
        "TARIF": 36
      },
      {
        "DAYFROM": 61,
        "DAYTO": 70,
        "TARIF": 40
      },
      {
        "DAYFROM": 71,
        "DAYTO": 80,
        "TARIF": 44
      },
      {
        "DAYFROM": 81,
        "DAYTO": 90,
        "TARIF": 49
      },
      {
        "DAYFROM": 91,
        "DAYTO": 120,
        "TARIF": 57
      },
      {
        "DAYFROM": 121,
        "DAYTO": 150,
        "TARIF": 68
      },
      {
        "DAYFROM": 151,
        "DAYTO": 180,
        "TARIF": 78
      },
      {
        "DAYFROM": 181,
        "DAYTO": 210,
        "TARIF": 86
      },
      {
        "DAYFROM": 211,
        "DAYTO": 240,
        "TARIF": 93
      },
      {
        "DAYFROM": 241,
        "DAYTO": 270,
        "TARIF": 98
      },
      {
        "DAYFROM": 271,
        "DAYTO": 99999999,
        "TARIF": 113
      }
    ]
  },
  "variantB": {
    "sumInsuredThirty": [
      {
        "DAYFROM": 1,
        "DAYTO": 3,
        "TARIF": 2
      },
      {
        "DAYFROM": 4,
        "DAYTO": 5,
        "TARIF": 3
      },
      {
        "DAYFROM": 6,
        "DAYTO": 8,
        "TARIF": 5
      },
      {
        "DAYFROM": 9,
        "DAYTO": 10,
        "TARIF": 6
      },
      {
        "DAYFROM": 11,
        "DAYTO": 12,
        "TARIF": 7
      },
      {
        "DAYFROM": 13,
        "DAYTO": 17,
        "TARIF": 10
      },
      {
        "DAYFROM": 18,
        "DAYTO": 21,
        "TARIF": 11
      },
      {
        "DAYFROM": 22,
        "DAYTO": 25,
        "TARIF": 14
      },
      {
        "DAYFROM": 26,
        "DAYTO": 29,
        "TARIF": 16
      },
      {
        "DAYFROM": 30,
        "DAYTO": 31,
        "TARIF": 17
      },
      {
        "DAYFROM": 32,
        "DAYTO": 35,
        "TARIF": 19
      },
      {
        "DAYFROM": 36,
        "DAYTO": 40,
        "TARIF": 21
      },
      {
        "DAYFROM": 41,
        "DAYTO": 44,
        "TARIF": 23
      },
      {
        "DAYFROM": 45,
        "DAYTO": 50,
        "TARIF": 25
      },
      {
        "DAYFROM": 51,
        "DAYTO": 56,
        "TARIF": 29
      },
      {
        "DAYFROM": 57,
        "DAYTO": 60,
        "TARIF": 30
      },
      {
        "DAYFROM": 61,
        "DAYTO": 70,
        "TARIF": 33
      },
      {
        "DAYFROM": 71,
        "DAYTO": 80,
        "TARIF": 37
      },
      {
        "DAYFROM": 81,
        "DAYTO": 90,
        "TARIF": 41
      },
      {
        "DAYFROM": 91,
        "DAYTO": 120,
        "TARIF": 48
      },
      {
        "DAYFROM": 121,
        "DAYTO": 150,
        "TARIF": 58
      },
      {
        "DAYFROM": 151,
        "DAYTO": 180,
        "TARIF": 66
      },
      {
        "DAYFROM": 181,
        "DAYTO": 210,
        "TARIF": 72
      },
      {
        "DAYFROM": 211,
        "DAYTO": 240,
        "TARIF": 78
      },
      {
        "DAYFROM": 241,
        "DAYTO": 270,
        "TARIF": 83
      },
      {
        "DAYFROM": 271,
        "DAYTO": 99999999,
        "TARIF": 95
      }
    ],
    "sumInsuredFifty": [
      {
        "DAYFROM": 1,
        "DAYTO": 3,
        "TARIF": 2
      },
      {
        "DAYFROM": 4,
        "DAYTO": 5,
        "TARIF": 4
      },
      {
        "DAYFROM": 6,
        "DAYTO": 8,
        "TARIF": 6
      },
      {
        "DAYFROM": 9,
        "DAYTO": 10,
        "TARIF": 7
      },
      {
        "DAYFROM": 11,
        "DAYTO": 12,
        "TARIF": 9
      },
      {
        "DAYFROM": 13,
        "DAYTO": 17,
        "TARIF": 12
      },
      {
        "DAYFROM": 18,
        "DAYTO": 21,
        "TARIF": 14
      },
      {
        "DAYFROM": 22,
        "DAYTO": 25,
        "TARIF": 17
      },
      {
        "DAYFROM": 26,
        "DAYTO": 29,
        "TARIF": 19
      },
      {
        "DAYFROM": 30,
        "DAYTO": 31,
        "TARIF": 21
      },
      {
        "DAYFROM": 32,
        "DAYTO": 35,
        "TARIF": 23
      },
      {
        "DAYFROM": 36,
        "DAYTO": 40,
        "TARIF": 25
      },
      {
        "DAYFROM": 41,
        "DAYTO": 44,
        "TARIF": 28
      },
      {
        "DAYFROM": 45,
        "DAYTO": 50,
        "TARIF": 30
      },
      {
        "DAYFROM": 51,
        "DAYTO": 56,
        "TARIF": 35
      },
      {
        "DAYFROM": 57,
        "DAYTO": 60,
        "TARIF": 37
      },
      {
        "DAYFROM": 61,
        "DAYTO": 70,
        "TARIF": 41
      },
      {
        "DAYFROM": 71,
        "DAYTO": 80,
        "TARIF": 45
      },
      {
        "DAYFROM": 81,
        "DAYTO": 90,
        "TARIF": 50
      },
      {
        "DAYFROM": 91,
        "DAYTO": 120,
        "TARIF": 59
      },
      {
        "DAYFROM": 121,
        "DAYTO": 150,
        "TARIF": 70
      },
      {
        "DAYFROM": 151,
        "DAYTO": 180,
        "TARIF": 80
      },
      {
        "DAYFROM": 181,
        "DAYTO": 210,
        "TARIF": 88
      },
      {
        "DAYFROM": 211,
        "DAYTO": 240,
        "TARIF": 95
      },
      {
        "DAYFROM": 241,
        "DAYTO": 270,
        "TARIF": 101
      },
      {
        "DAYFROM": 271,
        "DAYTO": 99999999,
        "TARIF": 116
      }
    ],
    "sumInsuredSeventy": [
      {
        "DAYFROM": 1,
        "DAYTO": 3,
        "TARIF": 3
      },
      {
        "DAYFROM": 4,
        "DAYTO": 5,
        "TARIF": 4
      },
      {
        "DAYFROM": 6,
        "DAYTO": 8,
        "TARIF": 7
      },
      {
        "DAYFROM": 9,
        "DAYTO": 10,
        "TARIF": 8
      },
      {
        "DAYFROM": 11,
        "DAYTO": 12,
        "TARIF": 10
      },
      {
        "DAYFROM": 13,
        "DAYTO": 17,
        "TARIF": 14
      },
      {
        "DAYFROM": 18,
        "DAYTO": 21,
        "TARIF": 16
      },
      {
        "DAYFROM": 22,
        "DAYTO": 25,
        "TARIF": 19
      },
      {
        "DAYFROM": 26,
        "DAYTO": 29,
        "TARIF": 22
      },
      {
        "DAYFROM": 30,
        "DAYTO": 31,
        "TARIF": 25
      },
      {
        "DAYFROM": 32,
        "DAYTO": 35,
        "TARIF": 27
      },
      {
        "DAYFROM": 36,
        "DAYTO": 40,
        "TARIF": 29
      },
      {
        "DAYFROM": 41,
        "DAYTO": 44,
        "TARIF": 33
      },
      {
        "DAYFROM": 45,
        "DAYTO": 50,
        "TARIF": 36
      },
      {
        "DAYFROM": 51,
        "DAYTO": 56,
        "TARIF": 41
      },
      {
        "DAYFROM": 57,
        "DAYTO": 60,
        "TARIF": 43
      },
      {
        "DAYFROM": 61,
        "DAYTO": 70,
        "TARIF": 48
      },
      {
        "DAYFROM": 71,
        "DAYTO": 80,
        "TARIF": 53
      },
      {
        "DAYFROM": 81,
        "DAYTO": 90,
        "TARIF": 59
      },
      {
        "DAYFROM": 91,
        "DAYTO": 120,
        "TARIF": 69
      },
      {
        "DAYFROM": 121,
        "DAYTO": 150,
        "TARIF": 82
      },
      {
        "DAYFROM": 151,
        "DAYTO": 180,
        "TARIF": 93
      },
      {
        "DAYFROM": 181,
        "DAYTO": 210,
        "TARIF": 103
      },
      {
        "DAYFROM": 211,
        "DAYTO": 240,
        "TARIF": 111
      },
      {
        "DAYFROM": 241,
        "DAYTO": 270,
        "TARIF": 118
      },
      {
        "DAYFROM": 271,
        "DAYTO": 99999999,
        "TARIF": 136
      }
    ],
    "sumInsuredHundred": [
      {
        "DAYFROM": 1,
        "DAYTO": 3,
        "TARIF": 3
      },
      {
        "DAYFROM": 4,
        "DAYTO": 5,
        "TARIF": 5
      },
      {
        "DAYFROM": 6,
        "DAYTO": 8,
        "TARIF": 7
      },
      {
        "DAYFROM": 9,
        "DAYTO": 10,
        "TARIF": 9
      },
      {
        "DAYFROM": 11,
        "DAYTO": 12,
        "TARIF": 11
      },
      {
        "DAYFROM": 13,
        "DAYTO": 17,
        "TARIF": 15
      },
      {
        "DAYFROM": 18,
        "DAYTO": 21,
        "TARIF": 18
      },
      {
        "DAYFROM": 22,
        "DAYTO": 25,
        "TARIF": 21
      },
      {
        "DAYFROM": 26,
        "DAYTO": 29,
        "TARIF": 24
      },
      {
        "DAYFROM": 30,
        "DAYTO": 31,
        "TARIF": 27
      },
      {
        "DAYFROM": 32,
        "DAYTO": 35,
        "TARIF": 29
      },
      {
        "DAYFROM": 36,
        "DAYTO": 40,
        "TARIF": 32
      },
      {
        "DAYFROM": 41,
        "DAYTO": 44,
        "TARIF": 36
      },
      {
        "DAYFROM": 45,
        "DAYTO": 50,
        "TARIF": 39
      },
      {
        "DAYFROM": 51,
        "DAYTO": 56,
        "TARIF": 44
      },
      {
        "DAYFROM": 57,
        "DAYTO": 60,
        "TARIF": 46
      },
      {
        "DAYFROM": 61,
        "DAYTO": 70,
        "TARIF": 52
      },
      {
        "DAYFROM": 71,
        "DAYTO": 80,
        "TARIF": 57
      },
      {
        "DAYFROM": 81,
        "DAYTO": 90,
        "TARIF": 64
      },
      {
        "DAYFROM": 91,
        "DAYTO": 120,
        "TARIF": 74
      },
      {
        "DAYFROM": 121,
        "DAYTO": 150,
        "TARIF": 89
      },
      {
        "DAYFROM": 151,
        "DAYTO": 180,
        "TARIF": 101
      },
      {
        "DAYFROM": 181,
        "DAYTO": 210,
        "TARIF": 112
      },
      {
        "DAYFROM": 211,
        "DAYTO": 240,
        "TARIF": 121
      },
      {
        "DAYFROM": 241,
        "DAYTO": 270,
        "TARIF": 128
      },
      {
        "DAYFROM": 271,
        "DAYTO": 99999999,
        "TARIF": 147
      }
    ]
  }
}

这是它的一小部分。它已经过验证。

虽然我试图通过以下方式获取数据:

var calcM = angular.module("calcM");
calcM.controller('calcMCtrl', ['$scope', function($scope, $http) {
        $scope.addRisk = {
            sport: "Sport",
            xSport: "xSport"
        };
        $scope.variants = {
            varA: "variantA",
            varB: "variantB",
            varD: "variantD"
        };

        $scope.limits = {
            "30000": 30000,
            "50000": 50000,
            "70000": 70000,
            "100000": 100000
        };

        $scope.data = {
            pickedOptions: {}
        };

        $scope.rates = {};

        $http.get("/CalculatorMed/JSON/rates.json/").then(function(data) {
        $scope.rates = data;

        });

    } ] );

我有一个错误:

错误:undefined不是对象(评估' $ http.get')

我做错了什么? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

您没有在控制器中注入$http,因此错误。

使用

calcM.controller('calcMCtrl', ['$scope', '$http', function($scope, $http) {
                                         //^^^^^^ Inject here