Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've already done with my first angular app. I have an error while calling a function. Here is a snippet of my JSON:

{

  "variantA": {
    "sumInsuredThirty": [
      {
        "dayFrom": 1,
        "dayTo": 3,
        "tarif": 2
      }, ...

I've got it via:

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

Now, I'm trying to get the tarif:

$scope.getBaseTarif = function () {
        var baseTarif = 0;
        if (data.pickedOptions.variantA === true && data.pickedOptions.sumInsured === 30000) {
            for (var i = 0; i < rates.variantA.sumInsuredThirty.lenght; i++) {
                if (data.pickedOptions.days >= rates.variantA.sumInsuredThirty[ i ].dayFrom && data.pickedOptions.days <= rates.variantA.sumInsuredThirty[ i ].dayTo) {
                    baseTarif = rates.variantA.sumInsuredThirty[ i ].tarif;
                    return baseTarif;
                }
            }
        }
      };

And I have an error:

Error: Can't find variable: data getBaseTarif@http://localhost:63342/CalculatorMed/controller/calculator.js:34:17 fn

Many thanks in advance!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
141 views
Welcome To Ask or Share your Answers For Others

1 Answer

data cannot be access outside, it should be $scope.rates,

 if ($scope.rates.pickedOptions.variantA === true && $scope.rates.pickedOptions.sumInsured === 30000) {
            for (var i = 0; i < rates.variantA.sumInsuredThirty.length; i++) {
                if ($scope.rates.pickedOptions.days >= rates.variantA.sumInsuredThirty[i].dayFrom && $scope.rates.pickedOptions.days <= rates.variantA.sumInsuredThirty[i].dayTo) {
                    baseTarif = rates.variantA.sumInsuredThirty[i].tarif;
                    return baseTarif;
                }
            }
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...