我已經完成了我的第一個角度應用程序。調用函數時出錯。 這裏是我的JSON的一個片段:Angular找不到變量:data
{
"variantA": {
"sumInsuredThirty": [
{
"dayFrom": 1,
"dayTo": 3,
"tarif": 2
}, ...
我已經通過了它:
$http.get("/CalculatorMed/JSON/rates.json/").then(function(data) {
$scope.rates = data.data;
});
現在,我試圖讓價格:
$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;
}
}
}
};
我有錯誤:
錯誤:找不到變量:data getBaseTarif @http://localhost:63342/CalculatorMed/controller/calculator.js:34:17 fn
非常感謝提前!
由於您的錯誤說:**什麼是數據**它不應該是'$ scope.rates'? – Mistalis
。長度拼寫不正確 – MMK
也應該是$ scope.rates = data; – MMK