This issue is very similar to Thingsboard Dashboard Custom Action NullInjectorError
I setup Entities table widget with Datasources from Entity alias like "Entity Views of type 'power_sensor'".
The idea is simple:
Now I'm going to create Custom action for “On row click ” but fail. I rty to modify @lee-sangjun's code according to entity.service API like this:
var $injector = widgetContext.$scope.$injector;
$injector.get(widgetContext.entityService.get('entityViewService')).getEntity(entityId.id).subscribe(function(entity) {
if (entity.name == 'Powermeter1') {
openDashboardState('energy_state_1')
}
else if(entity.name == 'Powermeter2') {
openDashboardState('water_state_2')
}
});
function openDashboardState(stateId) {
var params = {
entityId: entityId,
entityName: entityName
}
widgetContext.stateController.openState(stateId, params,
false);
}
But nothing happens. What I have to do to make it work?
Working solution I've found:
var $injector = widgetContext.$scope.$injector;
$injector.get(widgetContext.servicesMap.get('entityViewService')).getEntityView(entityId.id).subscribe(function(entity) {
console.log(entity)
if (entity.name == 'Powermeter1') {
openDashboardState('energy_state_1')
}
else if(entity.name == 'Powermeter2') {
openDashboardState('water_state_2')
}
});
function openDashboardState(stateId) {
var params = {
entityId: entityId,
entityName: entityName
}
widgetContext.stateController.openState(stateId, params,
false);
}
Where 'Powermeter1' and 'Powermeter2' are names of Entity Views. Hope it will be helpful.