18
marsApp.filter("transformSensorStatus", function($scope) {
return function(input, options) {
var sensorReading = (input ? (input/1000) : 0);
var sensorLowLimit = (options["lowLimit"] ? (options["lowLimit"]/1000) : 0);
var sensorHighLimit = (options["highLimit"] ? (options["highLimit"]/1000) : 0);
var curStat;
switch (sensorReading) {
case 255:
case 254:
case 253:
curStat = generateStateInnerHtml(sensorReading);
break;
default:
curStat = generateStateInnerHtml(options["sensorStatus"]);
}
return curStat;
function generateStateInnerHtml(state) {
var stateHtml = null;
if (state == 255 || state == 254) {
stateHtml = "a";
$scope.sensorStateColor='';
return state_html;
}
if (state == 253) {
stateHtml = "b";
$scope.sensorStateColor="text-warning";
return state_html;
}
if (state >= 0x20) {
stateHtml = "c";
$scope.sensorStateColor="text-error";
return stateHtml;
}
if (state >= 0x02) {
stateHtml = "d";
$scope.sensorStateColor="text-error";
return stateHtml;
}
if (state == 0x01) {
stateHtml = "e";
$scope.sensorStateColor="text-success";
return stateHtml;
}
stateHtml = "N/A";
return stateHtml;
}
}
});
在Chrome中,我得到以下錯誤:
Error: Unknown provider: $scopeProvider <- $scope <- transformSensorStatusFilter
是的,$ rootScope可用。 – dylan
**對瀏覽者的警告:**''rootScope'實質上是一個全局範圍。注意這個事實的含義;例如來自'$ rootScope'內部控制器的監視必須注意自己註銷,否則可能會發生內存泄漏。所以,僅僅因爲'$ rootScope'可用,這並不意味着要繼續並且不小心使用它。 –
謝謝,Angular 1.6.3仍然是一個有用的答案! – zaphodb