本文介绍了Angular找不到变量:数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经完成了我的第一个有角度的应用程序.调用函数时出现错误.这是我的JSON的代码段:
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
}, ...
我通过以下方式得到它
$http.get("/CalculatorMed/JSON/rates.json/").then(function(data) {
$scope.rates = data.data;
});
现在,我正在尝试获取tarif:
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;
}
}
}
};
我有一个错误:
错误:找不到变量:数据getBaseTarif @ http://localhost:63342/CalculatorMed/controller/calculator.js:34:17 fn
Error: Can't find variable: datagetBaseTarif@http://localhost:63342/CalculatorMed/controller/calculator.js:34:17fn
非常感谢!
推荐答案
数据不能在外部访问,应该是$ scope.rates,
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;
}
}
}
这篇关于Angular找不到变量:数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!