我很新,不僅要求幫助,而且還要使用Angular,所以請耐心等待。
下面是我使用的一個計算器.js代碼的副本,用於創建燈泡的能量級別 - 我目前停留在希望顯示可以對其他燈泡節省多少的點例如....
鹵素總 - 白熾燈總
hal_total - inc_total
有人會請這麼好心來看看我的代碼,也許我指出正確的方向。
/* JavaScript Document */
(function(){
var app = angular.module('myCalculator',[]);
app.controller('calculatorcontroller',['$scope',function($scope){
$scope.lumen_options = [375,600,900,1125,1600];
$scope.current_lumens = 600;
$scope.current_cost = 12;
$scope.current_hours = 3;
$scope.current_years = 1;
$scope.current_bulbs = 1;
$scope.total_days = 365;
$scope.inc_conversion = .0625;
$scope.hal_conversion = .0450;
$scope.cfl_conversion = .0146;
$scope.led_conversion = .0125;
$scope.calculate = function(){
$scope.inc_wattage = ($scope.current_lumens * $scope.inc_conversion).toFixed(1);
$scope.hal_wattage = ($scope.current_lumens * $scope.hal_conversion).toFixed(1);
$scope.cfl_wattage = ($scope.current_lumens * $scope.cfl_conversion).toFixed(1);
$scope.led_wattage = ($scope.current_lumens * $scope.led_conversion).toFixed(1);
if($scope.current_hours > 24){ $scope.current_hours = 24 }
var total_hours = $scope.total_days * $scope.current_hours;
var total_total = $scope.total_days * $scope.current_hours * $scope.current_years * $scope.current_bulbs;
var cost = $scope.current_cost/100;
$scope.inc_cost = ((($scope.inc_wattage * total_hours)/1000) * cost).toFixed(2);
$scope.hal_cost = ((($scope.hal_wattage * total_hours)/1000) * cost).toFixed(2);
$scope.cfl_cost = ((($scope.cfl_wattage * total_hours)/1000) * cost).toFixed(2);
$scope.led_cost = ((($scope.led_wattage * total_hours)/1000) * cost).toFixed(2);
$scope.inc_total = ((($scope.inc_wattage * total_total)/1000) * cost).toFixed(2);
$scope.hal_total = ((($scope.hal_wattage * total_total)/1000) * cost).toFixed(2);
$scope.cfl_total = ((($scope.cfl_wattage * total_total)/1000) * cost).toFixed(2);
$scope.led_total = ((($scope.led_wattage * total_total)/1000) * cost).toFixed(2);
}
$scope.calculate();
}]);
})();
你可以突出顯示不工作的代碼嗎? – nikhil
難道你不能只是把'{{hal_total-inc_total}}'放在你的控制器裏面的'div'內的html中嗎? – Cameron
你能否也顯示你的HTML代碼? –