I am faced with a set of table rows
<tr *ngFor="let firedRule of splitRules(results.rulesFired); let rowNumber = index"
[class.added]="isAdd(firedRule)"
[class.removed]="isRemove(firedRule)"
[class.modified]="isModify(firedRule)">
The splitRules function is responsible for breaking down rules into new properties:
splitRules(firedRules: FiredRule[]) {
const regExRowNumber = /row\s*([0-9]+)/;
let rowMatch = [];
firedRules.forEach(rule => {
let name = '';
name = rule.ruleName.toLowerCase();
rowMatch = regExRowNumber.exec(name);
const rowNumber = rowMatch[1];
const ruleName = name.substr(rowMatch[0].length).split('-')[0];
const conditionsMatched = name.substr(rowMatch[0].length).split('-')[1];
rule.groupName = ruleName.trim().replace('!', ': ').split(':')[0];
rule.definitionName = ruleName.trim().replace('!', ': ').split(':')[1];
rule.rowNumber = rowNumber;
rule.conditionsMatched = conditionsMatched.trim();
rowMatch = [];
});
return firedRules;
}
It's advised not to call the splitRules
method within html, so I attempted calling it on ngOnInit
:
@Input() results: RulesEngineResponse;
ngOnInit(): void {
this.results.rulesFired = this.splitRules(this.results.rulesFired);
}
However, upon removing the call from html, an error
ERROR TypeError: Cannot read property 'rulesFired' of null
occurred. Is there a way to resolve this issue?
Your assistance would be greatly appreciated.