gpt4 book ai didi

javascript - AngularJS - 无法总结范围上的属性

转载 作者:行者123 更新时间:2023-12-03 12:19:25 24 4
gpt4 key购买 nike

我在 Angular Controller 中有以下 Angular 代码:

代码:

$scope.orangeCrate.italian = {
"description": "Annual",
"payer": "farmer",
"farmerCost": 0,
"ownerCost": 21
};

$scope.orangeCrate.portugal = {
"description": "Annual",
"payer": "owner",
"farmerCost": 6.5,
"ownerCost": 0
};

$scope.orangeCrate.total = {
"farmerCost": $scope.orangeCrate.italian.farmerCost + $scope.orangeCrate.portugal.farmerCost,
"ownerCost": $scope.orangeCrate.italian.ownerCost + $scope.orangeCrate.portugal.ownerCost,
};

当我尝试将 $scope.orangeCrate.total.farmerCost 中的值打印到我的 View 上时,我什么也没得到,即使我应该得到 6.5!

我做错了什么?

最佳答案

这样的事情就可以了(抱歉“糟糕”的答案......我很着急):

$scope.orangeCrate = {
"italian": {
"description": "Annual",
"payer": "farmer",
"farmerCost": 0,
"ownerCost": 21
},
"portugal": {
"description": "Annual",
"payer": "owner",
"farmerCost": 6.5,
"ownerCost": 0
}
};
$scope.orangeCrate.total = {
"farmerCost": $scope.orangeCrate.italian.farmerCost + $scope.orangeCrate.portugal.farmerCost,
"ownerCost": $scope.orangeCrate.italian.ownerCost + $scope.orangeCrate.portugal.ownerCost,
};

关于javascript - AngularJS - 无法总结范围上的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24515245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com