Thingsboard 仪表板自定义操作 NullInjectorError
Thingsboard Dashboard Custom Action NullInjectorError
我尝试为“On row click”配置自定义操作,但 Firefox 和 Chromium 均失败并显示 NullInjectorError
。我不知道如何找到根本问题并解决它。
即使我重复 "ThingsBoard Dashboard development guide. Part 2" 视频教程代码示例(视频中的代码:https://youtu.be/mqWEGs1Z2BQ?t=589),它也会失败并出现相同的错误。
我的代码:
var $injector = widgetContext.$scope.$injector;
$injector.get('deviceService').getDevice(entityId.id).then(function(device){
if(device.type == 'energy sensor'){
openDashboardState('energy_state');
} else if(device.type == 'water sensor'){
openDashboardState('water_state');
} else if(device.type == 'temperature sensor'){
openDashboardState('temperature_state');
} else {
// fallback here if I mistaken with device.types
openDashboardState('temperature_state');
}
});
function openDashboardState(stateId){
var params = {
entityId: entityId,
entityName: entityName
};
widgetContext.stateController.openState(stateId, params, false);
}
我在 Chromiun 中的错误:
NullInjectorError: R3InjectorError(e)[deviceService -> deviceService -> deviceService -> deviceService]:
NullInjectorError: No provider for deviceService!
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:692603)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:764401)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:764401)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:764401)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:764401)
at t.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:862099)
at Object.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:846305)
at Qn (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:706656)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:708213)
at eval (eval at e.handleWidgetAction (http://my-server-addr:8880/1.22c948d0d38c2bc05630.js:1:584011), <anonymous>:5:11)
e.handleWidgetAction @ 1.22c948d0d38c2bc05630.js:1
e.onRowClick @ 1.22c948d0d38c2bc05630.js:1
e_mat_row_25_Template_mat_row_click_0_listener @ template.html:87
gl @ polyfills.e5ed3e112692f855567f.js:1
i @ polyfills.e5ed3e112692f855567f.js:1
(anonymous) @ polyfills.e5ed3e112692f855567f.js:1
e.invokeTask @ polyfills.e5ed3e112692f855567f.js:1
onInvokeTask @ polyfills.e5ed3e112692f855567f.js:1
e.invokeTask @ polyfills.e5ed3e112692f855567f.js:1
t.runTask @ polyfills.e5ed3e112692f855567f.js:1
t.invokeTask @ polyfills.e5ed3e112692f855567f.js:1
h @ polyfills.e5ed3e112692f855567f.js:1
f @ polyfills.e5ed3e112692f855567f.js:1
我检查了同样的问题。我找到了解决方案。
var $injector = widgetContext.$scope.$injector;
$injector.get(widgetContext.servicesMap.get('deviceService')).getDevice(entityId.id).subscribe(function(device) {
if (device.type == 'energy sensor') {
openDashboardState('energy_state')
}
else if(device.type == 'water sensor') {
openDashboardState('water_state')
}
else {
openDashboardState('temperature_state')
}
});
function openDashboardState(stateId) {
var params = {
entityId: entityId,
entityName: entityName
}
widgetContext.stateController.openState(stateId, params,
false);
}
希望对你有所帮助。祝你好运! :)
我尝试为“On row click”配置自定义操作,但 Firefox 和 Chromium 均失败并显示 NullInjectorError
。我不知道如何找到根本问题并解决它。
即使我重复 "ThingsBoard Dashboard development guide. Part 2" 视频教程代码示例(视频中的代码:https://youtu.be/mqWEGs1Z2BQ?t=589),它也会失败并出现相同的错误。
我的代码:
var $injector = widgetContext.$scope.$injector;
$injector.get('deviceService').getDevice(entityId.id).then(function(device){
if(device.type == 'energy sensor'){
openDashboardState('energy_state');
} else if(device.type == 'water sensor'){
openDashboardState('water_state');
} else if(device.type == 'temperature sensor'){
openDashboardState('temperature_state');
} else {
// fallback here if I mistaken with device.types
openDashboardState('temperature_state');
}
});
function openDashboardState(stateId){
var params = {
entityId: entityId,
entityName: entityName
};
widgetContext.stateController.openState(stateId, params, false);
}
我在 Chromiun 中的错误:
NullInjectorError: R3InjectorError(e)[deviceService -> deviceService -> deviceService -> deviceService]:
NullInjectorError: No provider for deviceService!
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:692603)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:764401)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:764401)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:764401)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:764401)
at t.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:862099)
at Object.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:846305)
at Qn (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:706656)
at e.get (http://my-server-addr:8880/polyfills.e5ed3e112692f855567f.js:1:708213)
at eval (eval at e.handleWidgetAction (http://my-server-addr:8880/1.22c948d0d38c2bc05630.js:1:584011), <anonymous>:5:11)
e.handleWidgetAction @ 1.22c948d0d38c2bc05630.js:1
e.onRowClick @ 1.22c948d0d38c2bc05630.js:1
e_mat_row_25_Template_mat_row_click_0_listener @ template.html:87
gl @ polyfills.e5ed3e112692f855567f.js:1
i @ polyfills.e5ed3e112692f855567f.js:1
(anonymous) @ polyfills.e5ed3e112692f855567f.js:1
e.invokeTask @ polyfills.e5ed3e112692f855567f.js:1
onInvokeTask @ polyfills.e5ed3e112692f855567f.js:1
e.invokeTask @ polyfills.e5ed3e112692f855567f.js:1
t.runTask @ polyfills.e5ed3e112692f855567f.js:1
t.invokeTask @ polyfills.e5ed3e112692f855567f.js:1
h @ polyfills.e5ed3e112692f855567f.js:1
f @ polyfills.e5ed3e112692f855567f.js:1
我检查了同样的问题。我找到了解决方案。
var $injector = widgetContext.$scope.$injector;
$injector.get(widgetContext.servicesMap.get('deviceService')).getDevice(entityId.id).subscribe(function(device) {
if (device.type == 'energy sensor') {
openDashboardState('energy_state')
}
else if(device.type == 'water sensor') {
openDashboardState('water_state')
}
else {
openDashboardState('temperature_state')
}
});
function openDashboardState(stateId) {
var params = {
entityId: entityId,
entityName: entityName
}
widgetContext.stateController.openState(stateId, params,
false);
}
希望对你有所帮助。祝你好运! :)