我需要获得以下示例的总计:
$scope.fees = {
basic: 1,
premium: 2,
total: this.basic + this.premium
}
为什么这不起作用?它说this
未定义。有没有办法无需写出 total: $scope.fees.basic + $scope.fees.premium
即可实现此目的.
如果有办法缩短它,我会很高兴。
编辑:我实际上必须添加 total
$scope.fees
之外的属性(property)。 $scope.fees.total = ...
最佳答案
您可以使用函数..
你好{{总计()}}function FeeController($scope) {
$scope.fees = {
basic: 1,
premium: 2,
};
$scope.total = function() {
return $scope.fees.basic + $scope.fees.premium;
};
}
关于javascript - 我可以使用 "this"访问范围对象本身的属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30200348/